如何将图像保存到磁盘(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);
相关问答
更多-
这是一种使用foreach ,它遍历数组的每个键,将其展开,并使用爆炸值作为新数组的键: $result = array(); foreach($array as $key => $value) { $new_keys = explode('.',$key); $last_key = array_pop($new_keys); //remove last key from $new_keys $a =& $result; //make $a and $result be the ...
-
$source = array( 0 => array ( 'name' =>'A', 'processer' => 'XMLf'), 1 => array ( 'name' =>'B', 'processer' => 'XMLp'), 2 => array ( 'name' =>'C', 'processer' => 'XMLp') ); $outp ...
-
是的,你不能在VB.Net中实例化那样的子项。 尝试只创建ListView项,然后将子项添加到它: Dim lvi As New ListViewItem(tuple.Item1) lvi.SubItems.AddRange({tuple.Item2, tuple.Item3}.ToArray()) ListView1.Items.Add(lvi) Yeah, you can't instantiate the subitems like that in VB.Net. Try just creating ...
-
如何将具有数组值的地图以优雅的方式转换为字符串列表?(How can I convert a map with array values to the list of strings in elegant way?)[2022-08-05]
虽然你可以使用Enum.flat_map ,但我相信一个for会更清楚: errors = %{ field_a: ["error 1", "error 2"], field_b: ["something here"] } formatted = for {field, messages} <- errors, message <- messages, do: "#{field} #{message}" IO.inspect formatted 输出: ["fiel ... -
请注意,这两个操作基本上都是原始数组的转置。 所有这些都是从这个答案中强烈改编的(考虑它的提升!)。 帮手 首先,我们需要一个帮助函数,它将行标题保存为关联数组中的键: function flipArrayKeys($arr) { $out = array('row' => array_keys($arr)); foreach ($arr as $key => $subarr) { foreach ($subarr as $subkey => $subvalue) { ...
-
Python - 将JSON键/值转换为键/值,其中value是数组(Python - Convert JSON key/values into key/value where value is an array)[2022-09-27]
Python字典有一个任意的排序,他们没有排序。 您希望使用预先编制的密钥列表来代替: with open('../json/routes_test.json') as json_data: datas = json.load(json_data) area_keys = ['area1','area2','area3','area4','area5'] type_keys = ['type1','type2','type3','type4'] for data in da ... -
从Object获取所有子项(Get all subitems from Object)[2022-04-22]
也许稍微更优雅: const inputvalues = Object.entries(this.entries) .map(([k, v]) => ([k, v.value])) .reduce((res, [k, v]) => (v !== undefined && (res[k] = v), res), {}); 或者少一些功能: const inputvalues = {}; for(const [key, obj] of Object.entries(this.entries)) ... -
将数组转换为键/值对(Convert array into key / value pairs)[2022-06-16]
使用简单的for循环。 var obj = ["blue", 1, "red", 4, "yellow", 2, "green", 7]; var res = []; for (var i = 0; i < obj.length; i += 2) { var o = {}; o[obj[i]] = obj[i + 1]; res.push(o); } console.log(res); 使用Array.from()方法的ES6解决方案。 let obj = ["blue ... -
将List [2022-07-26]
ListViewItem类有很多构造函数。 最适合您的情况是ListViewItem构造函数(String []) public ListViewItem(string [] items) 使用表示子项的字符串数组初始化ListViewItem类的新实例。 使用你的代码片段,就像这样 Products.Items.AddRange(basket.ProductList.Select(p => new ListViewItem(new string[] { p.Description, p. ... -
您需要检查属性键,索引0不保证 var newnwcontent = {} array.forEach(function(el) { var keys = Object.keys(el) var key = keys[0] == 'preview_image_url' ? keys[1] : keys[0] newnwcontent[key] = el }) You need to check the property keys, index 0 is not guaranteed var ...