I have a php code to upload file from my local system to AWS S3. and also I have php webpage which make user to upload a file and submit. now my requirement is I need to upload user uploaded file directly to AWS S3. Is there a way to upload file directly from UI to S3 without keeping it in system.? if there is a way how can I do that.
Thanks in advance.
Yes you can very much do that without keeping any system in between using sdk-for-javascript
You can refer to the sample web page that does exactly that.
Following is the code snippet from that page
function addPhoto(albumName) {
var files = document.getElementById('photoupload').files;
if (!files.length) {
return alert('Please choose a file to upload first.');
}
var file = files[0];
var fileName = file.name;
var albumPhotosKey = encodeURIComponent(albumName) + '//';
var photoKey = albumPhotosKey + fileName;
s3.upload({
Key: photoKey,
Body: file,
ACL: 'public-read'
}, function(err, data) {
if (err) {
return alert('There was an error uploading your photo: ', err.message);
}
alert('Successfully uploaded photo.');
viewAlbum(albumName);
});
}
For setting your credentials to the SDK from browser scripts following are the ways in order of recommendation:
More details about setting the credentials can be found here and here