- Send GET request to remote source for image
- Write response onto webserver as file
- Read file and upload to S3
Although each image would simply overwrite the previous one on the webserver, there really isn't a need for any additional disk writing to the webserver, since the end goal is only to copy the images up to S3:
- Send GET request to remote source for image
- Forward response to S3
The concept is fairly trivial, but still took me a good amount of time to nail down due to a bit of a quirk I wasn't aware of with the Node.js Request module. The modules used:
The biggest gotcha here was that the request module expects a String in the response body by default. To make sure the response stream is kept as raw bytes, the request should be considered to use null as the encoding . Related code:
I've only tried this so far with images, but it should work with just about any small file. Unfortunately, I am uncertain about how well this works with a large file, where memory issues may arise. Obviously, the code will need to be tweaked to fit your needs.
No comments:
Post a Comment