Reputation: 151
anyone else trying to Add products images using Signed AWS S3 urls.
The url end up having some additional attributes as &AWSAccessKeyId=AVEL2J32A6Q&Expires=1499769146&Signature=CDgIfiFlgDaD+0SHW1xvZ9A=
And something from this url affects the "BigCommerce" image parser and it returns error - The field 'image_file' is invalid.
Anyone has some workaround with "private" S3 files?
Upvotes: 0
Views: 246
Reputation: 151
Additional GET parameter "ResponseContentDisposition" was at fault. Removed it for this specific case and everything worked fine.
Upvotes: 0
Reputation: 1682
Adding product images to a product via the BigCommerce API while using S3 Signed URLs is indeed most definitely possible.
As stated in the comments above, you may just have an issue with the URL syntax for the signed URL. You need to urlencode the S3 URL before passing it to BigCommerce. Specifically, if you are generating the signature individually, be sure to urlencode it.
An example of a signed S3 URL looks like so...
'https://bucket-name.s3.amazonaws.com/folder/path/img.png?AWSAccessKeyId=key_id_here&Expires=1499804871&Signature=url_encoded_sig_here'
Here is an example of how to achieve your desired outcome programmatically while using the BigCommerce & AWS APIs with Node.js V6:
// Load AWS & BC Libraries:
const AWS = require('aws-sdk'); // npm install aws-sdk
const BC = require('./connection'); // wget https://raw.githubusercontent.com/mullinsr/bigcommerce-node.js/master/connection.js
// Configure the AWS SDK & Initialize the S3 Class:
AWS.config = new AWS.Config({
accessKeyId: 'access key ID here',
secretAccessKey: 'secret access key here',
region: 'us-east-1' // Enter region (N. Virginia = us-east-1 | Ohio = us-east-2 | N. California = us-west-1 | Oregon = us-west-2)
});
const s3 = new AWS.S3(); // Initialize S3 Class!
// Configure & Initialize the BC API Connection:
const settings = {
path: 'https://store-url.com',
user: 'username',
pass: 'apikey'
};
const api = new BC(settings); // Initialize BigCommerce API.
// Generate a signed URL:
const params = {
Bucket: 'your bucket name here, located in region set in AWS config',
Key: 'folder/path/image.png',
Expires: 10 // 10 Seconds until the URL should expire.
};
const url = s3.getSignedUrl('getObject', params); // Generate the URL!
// Define the BC Image Options (@see: https://developer.bigcommerce.com/api/v2/#create-a-product-image)
const img = {
image_file: url,
is_thumbnail: true
};
// Enter the Product ID that you wish to assign a product image to:
let pid = 5;
// Perform the API Request! :: Assign the image to the product!
api.post('/products/' +pid '/images', img).then(res => {
console.log('Successfully added image to product! Image ID = ', res.id);
}).catch(err => {
console.log('Caught Error: ', err);
});
Upvotes: 1