简体   繁体   English

Fileupload使应用程序停止

[英]Fileupload Makes application Stops

Here the code which i have used in my corodova 2.9.0 based application in Andorid .When i try to upload the photo.The Application gets crashed. 这是我在Andorid的基于corodova 2.9.0的应用程序中使用的代码。当我尝试上传照片时,该应用程序崩溃了。

function uploadPhoto(imageURI)
{
 Ext.Viewport.mask({ xtype: 'loadmask' });               
 var milliseconds = js_yyyy_mm_dd_hh_mm_ss();
 var options = new FileUploadOptions();
 options.fileKey="file";
 options.chunkedMode=false;         options.fileName=App.gvars.userid+milliseconds+imageURI.substr(imageURI.lastIndexOf('/')+1);
 renamedfile=options.fileName;
 options.mimeType="image/jpeg";
 var params = new Object();
 options.params = params;
 var ft = new FileTransfer();
 var url = "http://wish.brammies.com/itemimage/upload.php/";
 ft.upload(imageURI, url, win, fail, options,true);
 }
 function win(r)
 {
  console.log("Code = " + r.responseCode);
  console.log("Response = " + r.response);
  console.log("Sent = " + r.bytesSent);
 }
 function fail(error)
  {
   console.log("An error has occurred: Code = " + error.code);
   console.log("upload error source " + error.source);
   console.log("upload error target " + error.target);
 }

EDIT PHP code 编辑 PHP代码

<?php 
$folder = “/itemimage/”;
if (is_uploaded_file($_FILES['file']['tmp_name']))  {  
if (move_uploaded_file($_FILES['file']['tmp_name'], $folder.$_FILES['file']['name'])) {
     echo "File uploaded";
} else {
     echo "File not moved to destination folder. Check permissions";
};
} else {
 echo "File is not uploaded.";
};
//you get the following information for each file:
echo $_FILES['file']['name']."</br>"; //represents the name of file uploaded
echo $_FILES['file']['size']."</br>";   //represents the size of file uploaded
echo $_FILES['file']['type']."</br>"; //represents the mime type of file uploaded
echo $_FILES['file']['tmp_name']."</br>";
echo "fdggdr";
?>

Android running version 4.1.4 Android运行版本4.1.4

Please help me to solve the issue. 请帮我解决问题。

set options.chunkedMode=true; 设置options.chunkedMode = true;

When chunked mode is false the HTTP code on Android tries to buffer the entire transfer in memory before sending. 如果分块模式为false,则Android上的HTTP代码会在发送前尝试将整个传输缓冲在内存中。 With larger transfers 15 mb in your case but for other phones it will be even less as they will have less memory this will cause an OutOfMemory Exception to be thrown. 如果您的传输容量更大,则为15 mb,但对于其他手机,它将更小,因为它们的内存更少,这将引发OutOfMemory Exception。 Since an OOME should never be caught the application will crash. 由于永远不会捕获OOME,因此应用程序将崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM