I am new to Django and want to develop an application to upload videos on AWS S3 using Boto3.
Please guide me step-by-step on how to implement this?
As I am new it's little hard for me to understand.
Earlier I tried and created one Form with form.FileField() and it returns File Object but that fileobject I am not able to upload using boto3 as upload_fileObj method must require read implemented as a rb.
Thanks in advance and waiting for guidance.
You should first create a file from your File Object in /tmp/ directory.
After that you can use that file path to upload using upload_file
once you are sure that the file is uploaded successfully you can delete that file from /tmp/ directory.
Incase, file is not being properly uploaded you can retry it also.
Related
I can successfully upload file in the Google JSON API using [Objects: insert] by passing binary file content. I was curious if there is a way to upload by passing an open link in a JSON payload allowing GCP to retrieve the file. Thanks!
It seems Signed URLs can help you do this.
you can check here
https://cloud.google.com/storage/docs/access-control/signed-urls
I have a Django 2.x with python 3.6 site in Google Cloud, the app is in app engine flex. (my first app :)
My app has an upload page, where I am asking the user upload a JSON file (that is never kept in the site), what I do is open it and generate another file from it
I know that django depending on the size of the file it goes into memory but I was never able to use this functionality, so what I did in local env, was creating a folder that I called, temp_reports, so I created the files here, uploaded them into a bucket and then deleted them, from temp_reports.
So I was thinking, as the site is already in gcloud, if I can directly create these files into the bucket? or do I still need to generate them in the site and then upload them?
Now if it is from my site I keep getting the following error:
Exception Value:
[Errno 2] No such file or directory: '/home/vmagent/app/temp_reports/file_516A3E1B80334372ADB440681BB5F030.xlsx
I had in my app.yaml
handlers:
- url: /temp_reports
static_dir: temp_reports
Is there something I am missing? in order to use temp_reports?
Or how can I create a file directly into my bucket?
You can certainly use the Storage Bucket without having to upload the file manually. This can be done by Google Cloud Storage client library (Preferred Method) . It allows you to store and retrieve data directly from the Storage Bucket. Secondly, you can use Cloud Storage API to do the same functionality but requires more efforts to set it up.
You want to use the upload_from_string method from google.cloud.storage.blob.Blob.
upload_from_string(data, content_type='text/plain', client=None,
predefined_acl=None)
So to create a text file directly on the bucket you could do this:
storage_client = storage.Client()
bucket = storage_client.get_bucket(‘mybucket’)
blob = bucket.blob(‘mytextfile.txt’)
blob.upload_from_string('Text file contents', content_type='text/plain')
For more information you can refer to the following page:
https://googleapis.github.io/google-cloud-python/latest/storage/blobs.html#google.cloud.storage.blob.Blob.upload_from_string
I have a created a website which allows users to login by giving user name and password..Now i want to make an option which will allow the file from local machine to upload to a server.How can i do this?
Follow documentation on File Uploads
I´m stuck with an easy requirement, I appreciate any ideas!
First the enviroment: Django app deployed on Heroku with a Postgres DB and serving the static files from AWS S3.
I have a model with a FileField, and when I upload a file it is stored in a AWS S3 bucket.
I just need to read the file, write some text and save it again, it should be easy, right?
I managed to do it in dev in my laptop, but when I deploy the app to heroku I get a lot of errors like a file path error (I guess it tries to look for the aws bucket path in the heroku server), write permmissions and some others...
Am I doing something wrong? How can I achieve this?
Thx in advanced!
I was thinking wrong...
The solutions is to read and write directly in the defined storage:
from django.core.files.storage import default_storage
with default_storage.open(model.field.name, "w+") as f:
f.write("hello")
Hope this can be useful to anyone
For my Python app,I had completed the basic settings to interact with google drive api and found it working by a test upload of a CSV file. Now I need to upload an image from a url to a newly created folder named 'myappname' in Google Drive.
Thanks in advance
For now, there is no way you can directly upload file from url. There are two workaround I can think of
Download file and upload it back using Files.insert()
Use Save to Drive button
Using save to Drive button requires user interaction to click the button which might not be the one you want. In that case, downloading and uploading is the only way I can think of.