I am using an API to retrieve the image source url and sending a request.get(...) method to retrieve the image and send it over to S3 upload. On the local environment, it works perfectly fine, but on the live environment, it is returning an image with 0 bytes when it is uploaded to S3.
I have tried investigating if it was an issue with the S3 post method CORS configuration, but this did not have any changes.
Uploading an image from local and live from a generic google images link, same issue where local is fine, but live environment file sizes are 0 bytes.
Tried using the express cors middleware for the specific route, no changes.
function sendUrlImageToS3 (uri, filename) {
return new Promise(function (resolve, reject) {
const subFolder = 'uploads/';
const s3Auth = new aws.S3({ params: {
Bucket: `BUCKET_NAME`,
Key: `RANDOM_KEY_STRING`
}})
// Send a GET request to the uri provided, initiate retrieval of the response data object
// Send that as a body of the s3.upload and configure as public read
// Once confirmed, return promise as resolved or rejected
request.get(uri)
.on('response', (res) => {
if (res.statusCode === 200) {
s3Auth.upload({ Body: res, ACL: "public-read", CacheControl: '5184000'}, (err, data) => {
if (err) {
reject({ success: false, error: err, data: null });
}
resolve({ success: true, error: false, data });
})
}
})
});
// This is called like this...
sendUrlImageToS3(IMAGE_URL_STRING, RANDOM_STRING_NAME);
In the local environment, it sends the image to S3 bucket which is the same as the testing environment. When local environment loads it, I would expect it to be the same with the testing environment given that the bucket is the same. However, the upload from testing environment is a 0byte object.
I believe I have safely ruled out that the upload to S3 is not the issue, but rather the request.get(...) result. I logged out the result from the request in local and live and the rawHeader is (***'d the spot that was different between live and local):
// rawHeaders:
// [ 'Content-Type',
// 'image/jpeg',
// 'Cache-Control',
// 'public,max-age=315360001',
// 'X-Imgix-Content-DPR',
// '1',
// 'X-Content-Type-Options',
// 'nosniff',
// 'Last-Modified',
// 'Thu, 20 Jun 2019 2:50:45 GMT',
// 'X-Imgix-Render-ID',
// '000000006D424E84',
// 'Server',
// 'imgix-fe',
// 'Access-Control-Allow-Methods',
// 'GET',
// 'Access-Control-Allow-Origin',
// '*',
// 'Content-Length',
// '71879',
// 'Accept-Ranges',
// 'bytes',
// 'Date',
// 'Thu, 20 Jun 2019 02:50:45 GMT',
// 'Via',
// '1.1 varnish',
// 'Age',
// '0',
// 'Connection',
// 'close',
// 'X-Served-By',
// 'cache-dca17761-DCA',
// 'X-Cache',
// 'MISS',
// 'X-Cache-Hits',
// '0', <<< ***THIS ONE HERE IS 0, BUT IN LOCAL ENVIRONMENT SHOWS A BYTE SIZE SUCH AS '4015'
// 'X-Timer',
// 'S1560999046.569615,VS0,VE408' ],
How we can insert header and footer in google docs with google docs api using PHP code
Writing a new and appending a file in PHP without erasing contents
How to combine 2 arrays with the condition that 2 and 5 values will be from the second array?
How to keep the ?error on url if page extension not included?
Cannot find the answer after my research, help me with mysql [duplicate]
By linking a user from Cognito in Alexa, I generate a user objct in which the userId and accessToken
I adding swagger-jsdoc comments to existing express app with routers
Made a websocket server, I was wondering why you can't send non-stringified objects over the socket connectionI understand you can use JSON
I have using nodeJS and mongoose/mongoDB to build an APIConsider the following model for a generic Model (Gmodel):