In boto3 related documentation, examples of uploading files to Amazon S3 seem to be only for files already existing on the disk. How do I upload files that are selected by users from an HTML form input <input type="file" name="fileToUpload">?
I asked the same question on stackoverflow too, but not getting any answer so far.
You will need your page to be coded using python as your back-end or some other module. Then, you can pipe the file the user chooses to your script. Or, you can have them upload the file and run a script with that input file that is on your server.
However, this isn't really a boto question and is best left for stackoverflow.
Thanks.
Thanks @SamCyanide for the answer.
@yltang52 , let us know if you run into any boto3 issues once you get to the S3 upload part of your back end script.
@jamesls. I have to save the user-uploaded file first, and then upload it to S3 using put_object(). Well, it's not so troublesome after all. BTW, when will boto3 support uploading files to Google Cloud Storage?
OK, I managed to upload a file without saving it:
cloudFilename = 'someFilename'
session = boto3.session.Session(aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_KEY)
s3 = session.resource('s3')
s3.Bucket(AWS_BUCKET_NAME).put_object(Key=cloudFilename, Body=request.FILES['fileToUpload'])
where fileToUpload comes from the form input element: <input type="file" name="fileToUpload">
When can I use:
session = boto3.session.Session(gs_access_key_id=GS_ACCESS_KEY, gs_secret_access_key=GS_SECRET_KEY)
gs = session.resource('gs')
gs.Bucket(GS_BUCKET_NAME).put_object(Key=cloudFilename, Body=request.FILES['fileToUpload'])
Most helpful comment
When can I use: