So I have some static files stored in a uploads folder running in my node.js application, but their name and extension (all of them are PDFs) were replaced by a mysql CHAR(32) string reference in DB.
I need to serve them with a comprehensible name (autogenerated in server) and it's original extension back. Any hints?
You can accomplish this with HTTP headers.
Content-disposition: attachment; filename=Example.pdf
Content-type: application/pdf
Related
Is there any method to read the downloaded file content(not the file name) using node js? I'm getting my downloaded file content-disposition: attachment;filename=hello11.xlsx like this. I want provide the URI to my excel data extraction function. but couldn't figure out how to get the URI because my get Request returns nothing but a file downloaded to the browser.
I found a similar question but it's using java
I'm trying to use the Put Blob Rest API from Postman (at the moment) using also a code generated SAS.
If I set the body as binary in postman and I select my file everything works just fine - I get my file in the blob storage as expected.
However, if I send the file using a multipart/form-data the file is being uploaded, but I get additional data at the beginning of the file such as:
----------------------------515848534032814231487294
Content-Disposition: form-data; name="file"; filename="my_file.json"
Content-Type: application/json
Does anybody know why is that and how I could use multipart/form-data for uploading my file to the blob storage?
Thank you in advance!
This is the expected behavior when using multipart/form-data.
By using multipart/form-data, the boundary(like this ---515848534032814231487294) is auto-generated in the file. But the blob storage backend does not get rid of it(means remove these lines auto-generated).
And one more thing, multipart/form-data is mostly used in a web project, and you can write a function which is used to processing these extra lines in the backend.
I'm trying to create a .zip file by passing the returned body of an HTTP GET request to SharePoint's Create File.
Body is:
{
"$content-type": "application/zip",
"$content": "UEsDBBQACA...="
}
Shouldn't this just work? The docs only define the Create File field as "Content of the file." but that's not super informative...
I believe I've done this before with a file that was application/pdf and it worked. Unfortunately, I can't find that Logic App (I think it may have been an experiment I've since deleted).
I should note that the Create File action does create a valid .zip file, in that it's not corrupt, but archive is empty. It's supposed to contain a single .csv file.
I tried decoding the Base64 content and it's definitely binary data.
Any idea where I'm going wrong?
I test with Postman and when I use the form-data way to POST the request, I found the .zip file couldn't be open. Then I check the Logic App run history and I find the problem is if just use the triggerbody() as the file content it will fail.
This is because the triggerbody() not just have the $content, so I change the expression to triggerBody()['$multipart'][0]['body'] then it works and the .zip file is full.
I have an app which serves a dynamic html and some static files written in NodeJS/Express.
I deployed an AWS CloudFront distro in front of it, however only the HTML goes through, all the static files result in 404. The headers of the requests look like:
Age:116
Connection:keep-alive
Content-Length:170
Content-Security-Policy:default-src 'self'
Content-Type:text/html; charset=utf-8
Date:Mon, 09 Oct 2017 14:37:23 GMT
Server:nginx/1.6.2
Via:1.1 523db8f46d98334ac6b5debbf315e15b.cloudfront.net (CloudFront), 1.1 proxy1.xxx.yy (squid/4.0.17)
X-Amz-Cf-Id:5UYpluGn8TxUxsxmmDYYiZnjbOWbZ7iFFit55mmgcN6IbAJHCEAX6Q==
X-Cache:MISS from proxy1.xxx.yy
X-Cache:Error from cloudfront
X-Cache-Lookup:MISS from proxy1.xxx.yy:3128
X-Content-Type-Options:nosniff
X-Powered-By:Express
For info, my nodejs app runs in some port, and nginx reverse-proxies it to the domain I specified using proxy_pass.
As you can see I'm behind another proxy, but this cannot be the problem.
What I believe is happening is that my origin looks like mydomain.com/path/app_id and express serves static files from mydomain.com/.
Has anyone successfully deployed CloudFront in front of NodeJS/Express for static files? I really don't understand what the problem is..
Thanks!
To serve files from another path the flow is as follows:
Add all necessary origins (in this case mydomain.com/path/app_id AND mydomain.com (without trailing /))
Add behaviours on your ditribution for every file type. In this case static files are stored in different folders (like /img). So we can add behaviours for img/*, js/* and css/*. Then each behaviour can be set to a single origin. In this case we choose mydomain.com which was previously named Static files origin.
My first deploy to AWS.
The files are all in place, and index.html loads.
There are two files in a subdir, one .js and once .css.
They both return 200 but fail to load. Chrome sais it's the 'parser'.
After trying a few things, I noted that this property is causing it: ContentEncoding: "gzip".
If I remove this property the files are found correctly.
Am I using this property incorrectly?
I am using the Node AWS SDK via this great project: https://github.com/MathieuLoutre/grunt-aws-s3
You can witness this behavior for yourself at http://tidepool.co.s3-website-us-west-1.amazonaws.com/
If you specify Content-Encoding: gzip then you need to make sure that the content is actually gzipped on S3.
From what I see in this CSS file:
http://tidepool.co.s3-website-us-west-1.amazonaws.com/08-26_6483218-dirty/all-min.css
the actual content is not gzipped, but the Content-Encoding: gzip header is present.
Also keep in mind that S3 is unable to compress your content on the fly based on the Accept-Encoding header in the request. You can either store it uncompressed and it will work for all browsers/clients or store it in a compressed format (gzip/deflate) and it will only work on some clients that can work with compressed content.
You could also take a look at the official AWS SDK for Node.js.