Python Forum
Save a file uploaded from client-side without having to read into memory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save a file uploaded from client-side without having to read into memory
#4
(Nov-21-2019, 06:58 AM)andym118 Wrote: Is it possible to make the uploaded file go straight to the hard drive instead of memory though?

If the system is capable of sendfile(2), you can make a zero-copy from a socket to a file descriptor and reversed.
Here is a module, which supports it: https://pypi.org/project/pysendfile/
Under the hood they use mmap.

Another very important thing is following:
Quote:Also, it must be clear that the file can only be sent “as is” (e.g. you can’t modify the content while transmitting). There might be problems with non regular filesystems such as NFS, SMBFS/Samba and CIFS. For this please refer to proftpd documentation.

This means, that you can't modify the stream on the fly.

EDIT: It seems, that this has been implemented since Python 3.3: http://michaldul.com/python/sendfile/
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Save a file uploaded from client-side without having to read into memory - by DeaD_EyE - Nov-21-2019, 07:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open/save file on Android frohr 0 339 Jan-24-2024, 06:28 PM
Last Post: frohr
  Recommended way to read/create PDF file? Winfried 3 2,904 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,479 Nov-09-2023, 10:56 AM
Last Post: mg24
  how to save to multiple locations during save cubangt 1 565 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  save values permanently in python (perhaps not in a text file)? flash77 8 1,251 Jul-07-2023, 05:44 PM
Last Post: flash77
  read file txt on my pc to telegram bot api Tupa 0 1,137 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,128 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,305 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,721 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read csv file with inconsistent delimiter gracenz 2 1,208 Mar-27-2023, 08:59 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020