Sinan Bolel
The demo link was broken and is now fixed. Sorry!
An awesome, simple library for quickly uploading images in your Ionic App!
An open source plugin will upload image files to an S3 bucket.
Include image-upload.bundle.min.js in your app:
<script src="lib/image-upload.min.js"></script>
Or, to use this with the Amazon SDK included:
<script src="lib/image-upload.bundle.min.js"></script>
.controller('UploadController', function ($scope){
var imageUpload = new ImageUpload();
$scope.file = {};
$scope.upload = function() {
imageUpload.push($scope.file, function(data){
console.log('File uploaded Successfully', $scope.file, data);
$scope.uploadUri = data.url;
$scope.$digest();
});
};
})
File upload form HTML:
<ion-content ng-controller="UploadController">
<input class="bottom-marg-15" type="file" name="file" file="file">
<button class="button button-small button-full button-positive" ng-disabled="file.size&&false || uploadProgress>0" ng-click="upload()" ng-cloak="">Upload</button>
<img class="fit" ng-if="uploadUri" ng-src="{{uploadUri}}">
<a ng-href="{{uploadUri}}" ng-bind="uploadUri"></a>
</ion-content>
file
Directive:
.directive('file', function() {
return {
restrict: 'AE',
scope: {
file: '@'
},
link: function(scope, el, attrs){
el.bind('change', function(event){
var files = event.target.files;
var file = files[0];
if(file.size>0){
scope.file = file;
scope.$parent.file = file;
} else {
scope.file = {};
scope.$parent.file = {};
}
scope.$apply();
});
}
};
})
You are welcome to use the public S3 bucket that is preconfigured in src/image-upload.js
. This public bucket will only accept files with JPG and PNG extensions up to 10MB in size. The files are automatically deleted after 24 hours.
To use your own Amazon S3 bucket, change the information in src/image-upload.js
and uglify by running grunt
in Terminal from the project directory.
Below is a summary of Uploading To S3 With AngularJS by Cheyne Wallace
To setup an S3 bucket for use with the Ionic Image Upload plugin, we need to:
PutObject
action from the drop down list.arn:aws:s3:::your_bucket_name
Now your user has write-only access to the bucket.
Your policy is going to look something like this;
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt126637111000",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::your_bucket_name"
]
}
]
}
Go to the AWS S3 console, click your bucket, then click the Properties button. You'll use the "Add CORS Configuration" button to configure your bucket to only allow PUT requests from particular origins.
You can use the following sample config -- edit to reflect your development, production and staging environments.
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedOrigin>https://www.yourdomain.com</AllowedOrigin>
<AllowedOrigin>http://staging.yourdomain.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<ExposeHeader>x-amz-server-side-encryption</ExposeHeader>
<ExposeHeader>x-amz-request-id</ExposeHeader>
<ExposeHeader>x-amz-id-2</ExposeHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Expire the objects in this bucket after some short period to prevent malicious use. Your server side code should handle moving and deleting valid files so you can assume those that are left after 24 hours are not meant to be there.
Permanently Delete Only
" and set it for 1
day -- this will delete any objects in the bucket that are older than 1 day permanently.Now, you're ready to use this bucket in your Ionic Image Upload app!
Hey there! You'll need to log in before you can leave a comment here.
The demo link was broken and is now fixed. Sorry!
hi. thanks for this! how to use it with ionic without html form? 1/ i try to post recorded video : var video = file:///private/var/mobile/Containers/Data/Application/51EE533D-4253-42CB-8203-C62AF49B410C/tmp/output.mov 2/ via: imageUpload.push(video... Thanks!
Hi Abid, the plugin only works for image files (.png, .jpg, .jpeg, .gif). We can put together a version that works for video files, thanks for your feedback!
Bookmarked!
Hi great plugin! Can you make more clearly on document so we can know better how to use this plugin?
Hi Mike! Thank you, I'm happy to hear you enjoy it! I'll open source it tonight, and I'd love to go over any questions you may have. For anyone who has bought this so far, please email me and I'll refund you. Let's build amazing things, together!
hello, I can change the upload function of image-upload.js config to point to my personal server?
THIS PLUGIN IS NOW FREE AND OPEN SOURCE! <3
hkjhjkcs
hello, I can change the upload function of image-upload.js config to point to my personal server?
Hi Dulce, yes you can. See the instructions at https://github.com/sbolel/image-uploader
Can you post the policy setting for the bucket on the S3 side. I tried with your bucket and it works. Trying with my own bucket and it does not work. I suspect the policy setting. Any other ideas why?
Hi Razman, I've updated the repository with bucket config tutorial. Plugin: https://github.com/sbolel/image-uploader Demo App: https://github.com/sbolel/ionic-image-upload
Hello, one more question. How do i select the file from cordova camera? My app will take a picture with cordova.camera. I tried to pass to your function the whole file path but could not send over.
Razman, here is a full demo app: https://github.com/sbolel/ionic-image-upload
You need to pass a file, not the path of a file. See the `file` directive at https://github.com/sbolel/ionic-image-upload/blob/master/www/js/app.js
Hi! This is an awesome plugin. I'm getting an error and can't seem to figure it out: Error: Expected params.Body to be a string, Buffer, Stream, Blob, or typed array object Also, when I run 'ionic run ios', the content won't load but on Chrome it loads (Safari it doesn't). I was wondering why that was happening?
I am getting the same error : Uncaught (in promise) Expected params.Body to be a string, Buffer, Stream, Blob, or typed array object . did you find any solution for this issue ?
Thanks for the plugin! I did notice in GitHub you say include: "<script src="lib/image-upload.min.js"></script>" but the file name is: lib/image-uploader.min.js" small typo but hopefully it'll save someone some time.
Did you get it to work? After I add the bower components, it doesn't work for me.
Ya it doesn't work for me yet :( Getting the error "ReferenceError: ImageUpload is not defined". I'm thinking it's because the function name needs to be "ImageUploader" but when I do that I get another error. Still playing around with it to see if I can get it to work
ah I see, I'll post back here if I get it working
Hi! I apologize for being out of touch. I'll get back into this towards the end of this week. Thank you for trying it out! Please dont hesitate to submit PRs :)
Is it possible for me to see the full demo files including the html files so I can see where my error could be? I'm getting the error "ImageUpload is not defined"
Here it is Breanna: https://github.com/sbolel/ionic-image-upload
Is it possible for me to see the full demo files including the html files so I can see where my error could be? I'm getting the error "ImageUpload is not defined"
Here it is Breanna: https://github.com/sbolel/ionic-image-upload
Thanks for the plugin! I did notice in GitHub you say include: "<script src="lib/image-upload.min.js"></script>" but the file name is: lib/image-uploader.min.js" small typo but hopefully it'll save someone some time.
Did you get it to work? After I add the bower components, it doesn't work for me.
Ya it doesn't work for me yet :( Getting the error "ReferenceError: ImageUpload is not defined". I'm thinking it's because the function name needs to be "ImageUploader" but when I do that I get another error. Still playing around with it to see if I can get it to work
ah I see, I'll post back here if I get it working
Hi! I apologize for being out of touch. I'll get back into this towards the end of this week. Thank you for trying it out! Please dont hesitate to submit PRs :)
Hi! This is an awesome plugin. I'm getting an error and can't seem to figure it out: Error: Expected params.Body to be a string, Buffer, Stream, Blob, or typed array object Also, when I run 'ionic run ios', the content won't load but on Chrome it loads (Safari it doesn't). I was wondering why that was happening?
I am getting the same error : Uncaught (in promise) Expected params.Body to be a string, Buffer, Stream, Blob, or typed array object . did you find any solution for this issue ?
Can you post the policy setting for the bucket on the S3 side. I tried with your bucket and it works. Trying with my own bucket and it does not work. I suspect the policy setting. Any other ideas why?
Hi Razman, I've updated the repository with bucket config tutorial. Plugin: https://github.com/sbolel/image-uploader Demo App: https://github.com/sbolel/ionic-image-upload
Hello, one more question. How do i select the file from cordova camera? My app will take a picture with cordova.camera. I tried to pass to your function the whole file path but could not send over.
Razman, here is a full demo app: https://github.com/sbolel/ionic-image-upload
You need to pass a file, not the path of a file. See the `file` directive at https://github.com/sbolel/ionic-image-upload/blob/master/www/js/app.js
hello, I can change the upload function of image-upload.js config to point to my personal server?
Hi Dulce, yes you can. See the instructions at https://github.com/sbolel/image-uploader
hkjhjkcs
hi. thanks for this! how to use it with ionic without html form? 1/ i try to post recorded video : var video = file:///private/var/mobile/Containers/Data/Application/51EE533D-4253-42CB-8203-C62AF49B410C/tmp/output.mov 2/ via: imageUpload.push(video... Thanks!
hello, I can change the upload function of image-upload.js config to point to my personal server?
Hi Mike! Thank you, I'm happy to hear you enjoy it! I'll open source it tonight, and I'd love to go over any questions you may have. For anyone who has bought this so far, please email me and I'll refund you. Let's build amazing things, together!
Hi great plugin! Can you make more clearly on document so we can know better how to use this plugin?
Bookmarked!
Hi Abid, the plugin only works for image files (.png, .jpg, .jpeg, .gif). We can put together a version that works for video files, thanks for your feedback!
The demo link was broken and is now fixed. Sorry!
THIS PLUGIN IS NOW FREE AND OPEN SOURCE! <3
Hey there! You'll need to log in before you can leave a rating here.
{{ rating.comment }}
{{ rating.comment }}