This IBM StrongLoop recipe answers the often asked question of: "Using LoopBack, how can I convert or resize an image to a thumbnail before uploading to Amazon S3?"
This recipe demonstrates the following:
- Customization of the LoopBack loopback-component-storage module;
- Usage of the LoopBack configuration files;
- Usage of the Winston logging module;
- Customization of the LoopBack BootScripts
- Customization of the LoopBack Explorer
Clone this recipe project:
$ git clone <this project>
Inside your LoopBack project, install all the NPM dependencies:
$ npm install
By default, this recipe assumes that the user has an Amazon S3 account. To run the example you will need to provide your s3 bucket name, s3 region, s3 access key and s3 secret access key.
These values can be set in the projects server/config.local.js file or as environment varables:
$ export AWS_S3_BUCKET = YourS3BucketName
$ export AWS_S3_REGION = YourS3RegionName
$ export AWS_S3_ACCESS_KEY_ID = YourS3AccessKeyID
$ export AWS_S3_SECRET_ACCESS_KEY = YourS3SecretAccessKey
-
Step 1: Start the LoopBack API project.
$ node ./server/server.js -
Step 2: Launch the API Explorer at
http://localhost:3000/explorerto view the available action. -
Step 3: Create a container that will receive the uploaded image.
$ curl -i -X POST -H "Content-Type: application/json" -d '{"name":"recipe"}' http://localhost:3000/api/CloudStoreImages -
Step 4: Upload the image.
$ curl -i -X POST -H "Content-Type: multipart/form-data" -F "fileUpload=@./sample/sample.jpg" http://localhost:3000/api/CloudStoreImages/recipe/upload -
Step 5: Observe that the original image, along with three other resized images were uploaded to your S3 bucket.The images were uploaded into a directory matching the name of the Container you created in Step 2.
The number of resized images, and unique suffixes, are defined in theserver/config.jsonfile. Check for thecloudStoreImagesobject.
1.0.0
MIT
Dennis W. Ashby