Skip to content

Commit ab9323d

Browse files
authored
Update upload.js
1 parent df5d8bd commit ab9323d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

functions/upload.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@ export async function onRequestPost(context) { // Contents of context object
2929

3030
const fileId = new Date().getTime();
3131
const fileExtension = fileName.split('.').pop();
32-
const newFilePath = `/file/v1/${fileId}.${fileExtension}`;
33-
32+
const key=fileId+"."+fileExtension;
3433
try{
35-
await env.img_static.put(newFilePath,fileContent);
36-
const key=fileId+"."+fileExtension;
37-
await env.img_url.put(key, newFilePath, {
38-
metadata: { ListType: "None", Label: "None", TimeStamp: new Date().time()}
34+
await env.img_static.put(key,fileContent);
35+
await env.img_url.put(key, "", {
36+
metadata: { ListType: "None", Label: "None", TimeStamp: fileId}
3937
}
4038
);
4139
}catch(error){
4240
return new Response(`Upload fail`, { status: 400 });
4341
}
44-
return new Response(`[{\"src\":\"${newFilePath}\"}]`);
42+
return new Response(`[{\"src\":\"/file/v1/${newFilePath}\"}]`);
4543
}
4644

4745
async function parseMultipartFormData(request) {

0 commit comments

Comments
 (0)