Processing a file while its being uploaded in django - django

My Application requires client to upload a Huge file through a Form . Currently , django stores the file in temp folder and my view function gets hit only after the whole file is uploaded where i can access the file.
My requirement is to be able to get uploaded chunks as soon as they arrive at the server so that i can start the processing .
I checked , there is streaming HTTP response but nothing for HTTP request (POST from client)
Thanks

Related

How to get content of the post request file POSTMAN

I have a problem with sending files to some API. When I do it via my server some pdf files send correctly but some not. But when I send the same pdf via POSTMAN everything works just fine. I am not sure what is the reason (probably POSTMAN encodes it into base64 but from my server, I send it in binary - just a guess). Is there a way to get the sent request file content from postman so that I can imitate it and compare with the request on my server?

Microsoft Graph API - Error: The Content-Range header length does not match the provided number of bytes

I am trying to upload a file to the Shared Documents library of my SharePoint website. The files are of type PDF and HTML. I am running a Cold Fusion development environment and using CFHTTP commands to execute HTTP requests. I have been able push a POST command and a PUT command to the proper endpoints listed on this link below:
Link: https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#best-practices
I do not understand why but the first section that mentions the HTTP requests for creating an upload session is different than what was used in the example a little further. For my project, I am using the endpoint:
"/{variables.instance.microsoftGraphAPIURL}/drive/root:/{item-path}:/createUploadSession"
P.S. variables.instance.microsoftGraphAPIURL is a variable to a microsoft graph endpoint to our Sharepoint website
With better luck using PUT commands than POST commands for creating an Upload Session. I am able to receive an uploadURL, but the issue comes with trying to upload the file. For the file upload, I am trying to upload a file in the same directory with a file size of 114992 bytes. I keep getting "The Content-Range header length does not match the provided number of bytes." whenever I run my Put command to upload the file.
Thus, my Content-Range is "bytes 0-114991/114992" and my Content-Length is "114992". For the image below, I replaced the file with a pdf, but the original file was an HTML page at 114992 bytes. I want to use a resumable upload session to have one function for uploading image, HTML, and PDF files.
If anyone could tell me if there is an issue with my content headers or my upload session http request or anything else that is causing my issue, that would be amazing! Thank you.

Rendering images from REST response on localhost

I am trying to run a REST API on one port (8000) using django and consuming that API in an App running on port 9000 again using django.
My REST response is having an image field, now the problem is that i can not provide my desktop path in upload_to option in my API models and if i am giving the absolute path of API project in my App project index. Html, i get a browser error as "Not allowed to load resources from local path"
So i am having to create media folders with same name in both API and App projects and keeping image files in both and using only the file path from the REST response and rendering the image from App project itself.
Is there any way i can get away with this and consume the image from the Rest response only?
You need to convert image to base64 in server side then send those base64 string as response . Then consume this base64 string as response in calling api. Then use it accordingly either save in filesysyem or in database . But make sure to converse base 64 image string to bytes.

MS GRAPH API Upload v1.0 endpoint corrupts DOCX

Was trying to upload docx files through a golang server using MS graph API, and although I was able to upload pdfs, when I tried uploading docx files the files were being corrupted when sent over. If I upload the same file through the OneDrive website, there would be no problems.
To isolate the issue I tried making the API calls through postman using a link like:
https://graph.microsoft.com/v1.0/users/pqv2-dev-svc#novacoast.com/drives/{drive-id}/items/{item-id}:/filename.docx:/content
used a bearer token.
the additional header of Content-Type of which I have tried the values:
text/plain
application/x-www-form-urlencoded
application/vnd.openxmlformats-officedocument.wordprocessingml.document
and uploaded the file with the form-data option under the body tab but with no luck, the file always gets corrupted.
Any ideas?
[Resolved] Was sending file as form-data instead of binary!

Flask unable to receive chunked data

I am kinda newby in python thus the question.
I am trying to create a simple http web server that can receive chunked data from a post request.
I have realized later that once a request sends a headers with chunked data, the Content-length headers will be set to zero, thus reading the sent data with 'request.get_data()' will fail.
Is there another way of reading the chunked data?
The request I receive does give me the data length in the 'X-Data-Length' headers.
Did you write both of the js upload file code and the flask in backend to handle upload request? If not then you will need some help with js to upload it.
One way to achieve chucked data upload is:
Chucked that file in the frontend with js. Give it some headers in the request for the total size, number of the chunk, chunk size... and send each chuck in a separate POST request (You can use dropzone.js for example, they will do the job for you, just need to config the params)
In the backend, create an upload API which will read the request headers and merge the file chunks back together