Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): revert back to put as multipart seemed to be causing lambda issue #425

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/web/src/app/api/video/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { timeStampUTC } from "@lib/time";
import { NextResponse } from "next/server";
import { getSession } from "@lib/session";
import { RESPONSE_NOT_AUTHORIZED } from "@lib/response";
import { getTmpBucket, uploadArtifactFromFileRef } from "@lib/s3";
import { getTmpBucket, putArtifactFromFileRef } from "@lib/s3";

const allowedMimeTypes = [
"video/mp4", // mp4
Expand Down Expand Up @@ -56,18 +56,18 @@ export async function POST(req: Request) {
}

try {
// filename = await s3Upload(file, userID);
// determine the path to write the file to
const extension = path.extname(file.name);
// file name extracted from request
const fileBaseName = path.basename(file.name, extension);
// file name combined with userID and timestamp
const filename = `${userID}-${fileBaseName}-${timeStampUTC()}${extension}`;
await uploadArtifactFromFileRef({
tthvo marked this conversation as resolved.
Show resolved Hide resolved
await putArtifactFromFileRef({
bucket: getTmpBucket(),
key: filename,
file: file,
});

return Response.json(
{ data: { success: true, filePath: filename } },
{ status: 200 },
Expand Down
19 changes: 8 additions & 11 deletions app/web/src/lib/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { S3Client } from "@aws-sdk/client-s3";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage";
import fs, { PathLike } from "fs";
import path from "path";
Expand Down Expand Up @@ -70,21 +70,18 @@ export async function uploadArtifactFromPath({
return await s3Upload.done();
}

export async function uploadArtifactFromFileRef({
export async function putArtifactFromFileRef({
bucket,
key,
metadata,
file,
}: S3FileUploadConfig) {
const buffer = Buffer.from(await file.arrayBuffer());
const s3Upload = new Upload({
client: client,
params: {
Bucket: bucket,
Key: key,
Metadata: metadata,
Body: buffer,
},
const putCommand = new PutObjectCommand({
Bucket: bucket,
Key: key,
Metadata: metadata,
Body: buffer,
});
return await s3Upload.done();
return await client.send(putCommand);
}
Loading