無法手動將圖像保存在磁盤上(Nginx,Django)

[英]Cannot manualy save image on disk (Nginx, Django)


I have a problem with custom uploading view from form. The problem starts when i am trying to save to /pathto/static/media/temp/. Django settings MEDIA_ROOT=/pathto/static/media, STATIC_ROOT=/pathto/static. Here's the code:

我從表單自定義上傳視圖時遇到問題。當我嘗試保存到/ pathto / static / media / temp /時,問題就開始了。 Django設置MEDIA_ROOT = / pathto / static / media,STATIC_ROOT = / pathto / static。這是代碼:

def upload_picture(request):
    temp_file = request.FILES['picture'].read()
    image_file = BytesIO(temp_file)
    im = Image.open(image_file)
    im.save('/pathto/static/media/temp/image.jpg')
    ...

Permissions for /pathto/static/media/temp/ directory

/ pathto / static / media / temp /目錄的權限

drwxrwxrwx 2 root root 4096 ... temp

Nginx config

Nginx配置

server  {
    location /media/  {
        alias /pathto/static/media/;
    }
    location /static/ {
        alias /pathto/static/;
    }
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://127.0.0.1:9000;
    }
}

Definitely everything is ok, if DEBUG=True because Django starts to serve files. So probably the problems with Nginx config.
How can i fix the problem with manualy saving the image?

絕對一切都沒問題,如果DEBUG = True,因為Django開始提供文件。所以可能是Nginx配置的問題。如何通過手動保存圖像來解決問題?

1 个解决方案

#1


1  

If I got your problem right the issue in

如果我把問題解決了問題

im.save('/pathto/static/media/temp/image.jpg')

Solution is:

解決方案是:

On Ubuntu

在Ubuntu上

sudo apt-get install libjpeg-dev

And then

接着

pip install -I pillow

It should help

它應該有所幫助


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/04/05/729a1919f62fb622288f6907d75ef903.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com