Uploading text file in server using django - django

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

Related

apply form data from Django website to .exe file to generate link

I have built a Django website to accept data submitted from a user input form (an e-book application website). Upon application by the user, I could see their application on the backstage of the website and approve their application. This website is used only for several people.
I want to add a function like this:
The users who have accounts on this website could submit a request to download the e-book, in which they should write the details (author, year.... ) of the e-book.
I have already made an .exe file, which could accept parameters (author, year...) to generate a .txt file (the e-book). I want to create an auto parameter passing function in my Django website. when I approve the users' application for the e-books on my website, the parameters they entered should be passed to the .exe file to generate the .txt file automatically and save this .txt file on the server.
At the same time, a link that is linked to the storage position of the .txt file should be shown to the user so they could download the .txt file generated.
I have tried to deploy my Django project to pythonanywhere, but it's a linux server and so the .exe file could not be run on it.
I have these 2 questions:
Are there any free Windows server options to deploy my Django website to so that I could let the .exe file run in the backstage?
How to achieve the functionality of passing the parameters that the user entered to the .exe file automatically and show the link to the user for downloading (I have finished all the other functionality of the website, including storing the parameters they entered to the sqlite database)?

Django google app engine No such file or directory

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

Django application to upload videos on S3 using boto3

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.

Where should I store user uploaded pics and files

I am working on a django app to store user pics and photos.
What is the optimal approach to store individual user media.
File Sizes are no more than 5MB.
The data is persistent.
The approach i have in mind is:
On form data submission, Upload it to an FTP server using django-storages.
Store the url and fetch it via http later for user.
How to save upload files to another server
I have seen the answers and I don't know what type of queue needs to be used.
you'd usually save the file locally and then latter upload it to some cloud service asynchronously, preferably using something like django-celery
see this answer

python upload image from a url to google drive api

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.