首页 \ 问答 \ 如何将图像保存到磁盘(how save image to disk)

如何将图像保存到磁盘(how save image to disk)

我在移动应用程序上工作,用户可以上传图像,我在服务器端使用Django。

我有两种方式获得图像,我想在除外的情况下将图像保存到磁盘。

imageFile = request.FILES['image']
try:
    file_path = imageFile.temporary_file_path()
except AttributeError as e:
    logger.debug(virtualFile')
    imageStringBuffer = imageFile.read()
    virtualFile = StringIO.StringIO(imageStringBuffer)
    # want to  save the  imageStringBuffer to disk

我想将'virtualFile'(除例外)保存到磁盘,我该怎么办?


I working on a mobile application, where user can upload images, am using Django in server side.

I got images in two ways, I want to save the image to disk in the except case.

imageFile = request.FILES['image']
try:
    file_path = imageFile.temporary_file_path()
except AttributeError as e:
    logger.debug(virtualFile')
    imageStringBuffer = imageFile.read()
    virtualFile = StringIO.StringIO(imageStringBuffer)
    # want to  save the  imageStringBuffer to disk

I want to to save the 'virtualFile' (in except case) to the disk , How can I do it?


原文:https://stackoverflow.com/questions/17693231
更新时间:2023-05-08 17:05

最满意答案

$source = array( 
    0 => array ( 
        'name' =>'A',
        'processer' => 'XMLf'),
    1 => array (
            'name' =>'B',
            'processer' => 'XMLp'),
    2 => array (
            'name' =>'C',
            'processer' => 'XMLp')
);

$output = array_map(function ($value) {
    return $value['name'];
}, $source);

print_r($output);

$source = array( 
    0 => array ( 
        'name' =>'A',
        'processer' => 'XMLf'),
    1 => array (
            'name' =>'B',
            'processer' => 'XMLp'),
    2 => array (
            'name' =>'C',
            'processer' => 'XMLp')
);

$output = array_map(function ($value) {
    return $value['name'];
}, $source);

print_r($output);

相关问答

更多