如何生成可查看的s3 url nodejs

时间:2023-02-11 23:07:11

I use the below code to get the signed url. I am getting a signed url and once i open the url its downloading the file. But i want a url where i can show the file. Like opening file in a new tab.

我使用下面的代码来获取签名的URL。我收到一个签名的网址,一旦我打开网址下载文件。但我想要一个我可以显示文件的网址。就像在新标签中打开文件一样。

I am using aws-sdk package and generate s3 as below

我正在使用aws-sdk包并生成如下的s3

const s3 = new AWS.S3();

s3.getSignedUrl('getObject', {
            Expires: options.expires || 300,
            Bucket: config.awsBucket,
            Key: key,
            // ACL: 'public-read',
            ResponseContentDisposition :'inline;filename=report.pdf'}, 
          function(err, url) {
            if (err) {
                return deferred.reject(err);
            }
            return deferred.resolve(url);
        });

Does anyone know how to generate a url where i can show the file.

有谁知道如何生成一个我可以显示该文件的网址。

1 个解决方案

#1


0  

If you didn't set the Content-Type correctly when you uploaded the file, this behavior is to be expected, because the default type is binary/octet-stream, which the browser correctly determines cannot be displayed inline.

如果在上载文件时未正确设置Content-Type,则会出现此行为,因为默认类型为binary / octet-stream,浏览器正确确定无法以内联方式显示。

You can work around it by setting ResponseContentType in your getSignedUrl() request to the correct value.

您可以通过将getSignedUrl()请求中的ResponseContentType设置为正确的值来解决此问题。

The correct type for a PDF file is application/pdf.

PDF文件的正确类型是application / pdf。

#1


0  

If you didn't set the Content-Type correctly when you uploaded the file, this behavior is to be expected, because the default type is binary/octet-stream, which the browser correctly determines cannot be displayed inline.

如果在上载文件时未正确设置Content-Type,则会出现此行为,因为默认类型为binary / octet-stream,浏览器正确确定无法以内联方式显示。

You can work around it by setting ResponseContentType in your getSignedUrl() request to the correct value.

您可以通过将getSignedUrl()请求中的ResponseContentType设置为正确的值来解决此问题。

The correct type for a PDF file is application/pdf.

PDF文件的正确类型是application / pdf。