I am creating a file in /tmp; say /tmp/x.docx. After that using pypandoc I transform it into /tmp/x.pdf
This works perfectly, but:
- I cannot see (ls /tmp) the files in /tmp
- Everything works well (I can return the pdf file x.pdf fo the user), using HttpResponse…
… and there is no os.remove( ) in my code.
Where are my files stored ?
I know there exist temporary files in Django, which may be is a better solution than writing in /tmp, but I would like to understand…
Thierry
Please post the actual code involved with creating and returning the file. Also describe your deployment environment in more detail. (e.g. Is anything like docker involved here?) I’d guess (with no other information yet) that what you think is the root isn’t the root for your process.
Ok.
Docker : no
Just running Django with apache2 and wsgi.
My code:
hee,
-ff is something like “xxx.odt”
-exten is: “odt”
-to is “md” or “pdf”
(Attachment tdumont50.vcf is missing)
ust running Django with apache2 and wsgi.
My code:
here,
-ff is something like “xxx.odt”
-exten is: “odt”
-to is “md” or “pdf”
with open(“/tmp/”+ff, ‘wb+’) as destination:
for chunk in ff.chunks():
destination.write(chunk)
dest=ff.replace(exten,to)
pypandoc.convert_file("/tmp/"+ff, to,outputfile="/tmp/"+dest)
Above, pypandoc reads from “/tmp/”+ff and writes to “/tmp/”+dest.
Then:
with open(“/tmp/”+dest,“rb”) as fh:
response = HttpResponse(fh.read(),
content_type=‘application/’+to)
response[‘Content-Disposition’] = ‘inline;filename=/tmp/’+dest
return response
That’s all. It works perfectly.
(Attachment tdumont50.vcf is missing)
And you’re running this code in a Django view?
Also, you mentioned:
Are you not seeing any files? Or just not seeing the file you’re looking for?
(If you’re not seeing any files, then it’s possible that the account you’re using doesn’t have permissions to see the files there.)
You can also use the find command to help find where the file is located.
Someone replied to your post.
[KenWhitesell] KenWhitesell <Django Forum
February 1
And you’re running this code in a Django view?
Yes
Also, you mentioned:
Thierry-Dumont:
I cannot see (ls /tmp) the files in /tmp
Are you not seeing /any/ files? Or just not seeing the file you’re
looking for?
No, I see all the files in /tmp (as any Unix user can do)
(Attachment tdumont50.vcf is missing)
hi 
just to be sure, you didn’t reboot or shutdown your system? anything in /tmp will be deleted once your system goes down
Someone replied to your post.
[amirreza8002] amirreza8002 <Django Forum
amirreza8002>
February 1
hi 
just to be sure, you didn’t reboot or shutdown your system? anything in
/tmp| will be deleted once your system goes down
No.
This morning (it’s 5 pm here) I changed my code, using
NamedTemporaryFile’s , which is
certainly more "Django’ish).
If you create a NamedTemporaryFile, say by:
destination = NamedTemporaryFile(delete=True, suffix=“.”+exten,
prefix=pref)
you can do:
print(destination.name)
and what you get is something like: /tmp/
This /tmp directory is certainly not the Linux /tmp one, but (I think)
some pseudo-directory stored in the ram (like /tmp in modern Linux, but
not the same).
So I wonder if, when you open a file in /tmp using
with open(something,“wb”) as f:
…
you create it in this in memory directory or not.
It’s just an idea.
Thierry
(Attachment tdumont50.vcf is missing)
What is your Apache configuration for your Django project?
Someone replied to your post.
[KenWhitesell] KenWhitesell <Django Forum
February 1
What is your Apache configuration for your Django project?
This is:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
Alias /media/ /home/webserver/Acsite/media/
Alias /static/ /home/webserver/Acsite/static/
Alias /favicon.ico /home/webserver/Acsite/static/img/favicon.ico
<Directory /home/webserver/Acsite/static>
Require all granted
</Directory>
<Directory /home/webserver/Acsite/media>
Require all granted
</Directory>
<Directory /home/webserver/Acsite/Acsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess Acsite python-home=/home/webserver/webserverenv
python-path=/home/webserver/Acsite
WSGIProcessGroup Acsite
WSGIScriptAlias / /home/webserver/Acsite/Acsite/wsgi.py
WSGIScriptReloading On
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile
/etc/letsencrypt/live/academie-sbla-lyon.fr-0001/cert.pem
SSLCertificateKeyFile
/etc/letsencrypt/live/academie-sbla-lyon.fr-0001/privkey.pem
SSLCertificateChainFile
/etc/letsencrypt/live/academie-sbla-lyon.fr-0001/chain.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
My mods enabled:
access_compat.load deflate.conf mpm_prefork.load setenvif.conf
alias.conf deflate.load negotiation.conf setenvif.load
alias.load dir.conf negotiation.load socache_shmcb.load
auth_basic.load dir.load php8.2.conf ssl.conf
authn_core.load env.load php8.2.load ssl.load
authn_file.load filter.load proxy.conf status.conf
authz_core.load headers.load proxy_http.load status.load
authz_host.load include.load proxy.load wsgi.conf
authz_user.load mime.conf reqtimeout.conf wsgi.load
autoindex.conf mime.load reqtimeout.load
autoindex.load mpm_prefork.conf rewrite.load
I think this is all.
Yours,
Thierry
(Attachment tdumont50.vcf is missing)
Look for a directory named '/tmp/systemd-private-(some long identifier)-apache2.service-(another identifier)/tmp` and search for your files in it.
If your system isn’t running systemd, look for any directory within /tmp with apache2 as part of its name.
Someone replied to your post.
[KenWhitesell] KenWhitesell <Django Forum
February 1
Look for a directory named '/tmp/systemd-private-(some long identifier)-
apache2.service-(another identifier)/tmp` and search for your files in it.
If your system isn’t running systemd, look for any directory within |/
tmp> with |apache2| as part of its name.
Great !
(I am in debian trixie, so it is systemd)
My files are in:
/tmp/systemd-private-acd7116ad20147449b1f90eaafaa2da4-apache2.service-n4SVt5/tmp/
Problem was solved !
Thanks again.
Thierry
(Attachment tdumont50.vcf is missing)