admin管理员组文章数量:1356716
I'm trying to upload an excel file into S3 and download it via a signedURL. What I've noticed is that the object es back in a different file-type instead of the expected xlsx type, and thus is unreadable locally.
I have two lambdas, one for uploading the object and another for retrieving the signedURL.
Upload:
async function () => {
const s3 = new aws.S3({ signatureVersion: 'v4' })
const params = {
Bucket: bucket,
Key: key
}
try {
const signedURL = await s3.getSignedUrl('getObject', params)
return response(200, signedURL)
} catch (err) {
console.log(JSON.stringify(err))
return response(400, err)
}
}
GetSignedURL:
async function () => {
const s3 = new aws.S3({ signatureVersion: 'v4' })
const params = {
Bucket: bucket,
Key: key
}
try {
const signedURL = await s3.getSignedUrl('putObject', params)
return response(200, { signedURL, key })
} catch (err) {
return response(400, err)
}
}
I'm guessing that the file doesn't actually get saved with its original file-type and S3 actually just converts it to text-file. Maybe I need an additional parameter or package to explicitly save it as an Excel file. Please let me know your thoughts!
I'm trying to upload an excel file into S3 and download it via a signedURL. What I've noticed is that the object es back in a different file-type instead of the expected xlsx type, and thus is unreadable locally.
I have two lambdas, one for uploading the object and another for retrieving the signedURL.
Upload:
async function () => {
const s3 = new aws.S3({ signatureVersion: 'v4' })
const params = {
Bucket: bucket,
Key: key
}
try {
const signedURL = await s3.getSignedUrl('getObject', params)
return response(200, signedURL)
} catch (err) {
console.log(JSON.stringify(err))
return response(400, err)
}
}
GetSignedURL:
async function () => {
const s3 = new aws.S3({ signatureVersion: 'v4' })
const params = {
Bucket: bucket,
Key: key
}
try {
const signedURL = await s3.getSignedUrl('putObject', params)
return response(200, { signedURL, key })
} catch (err) {
return response(400, err)
}
}
I'm guessing that the file doesn't actually get saved with its original file-type and S3 actually just converts it to text-file. Maybe I need an additional parameter or package to explicitly save it as an Excel file. Please let me know your thoughts!
Share Improve this question asked Feb 6, 2020 at 19:20 Cat_EnthusiastCat_Enthusiast 15.7k5 gold badges25 silver badges46 bronze badges1 Answer
Reset to default 6You are missing the ContentType in params. Im not sure if this one is the right one for excel but providing the correct content type should address the issue. I had a similar issue when uploading images. I forgot to set the ContentType to image/jpeg
const params = {
Bucket: bucket,
Key: key,
ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
Other possible options "xls" => "application/vnd.ms-excel", "xlsx" => "vnd.ms-excel",
本文标签: javascriptS3 Uploading Excel File and Downloading it via SignedURLStack Overflow
版权声明:本文标题:javascript - S3 Uploading Excel File and Downloading it via SignedURL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744005003a2574539.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论