air file download I/O error : #2038
hi, i'm mina.
I uploaded a file with a file size of 0byte to the server, and the upload was successful.
(A file with no content and only a title.)
but, If the file size on the server is zero during adobe air download, an io error occurs.
When downloading directly to the server side api url, the file is flushed well.
Download using bufferedInputStream and bufferedOutputStream. When downloading air itself, the io error log is ioErrorHandler: Error #2038: File I/O Error. URL: http://xx.xx.x.xxx:8080/test/download. How can I download a file with a file size of 0? I need help..
this is my code flex :
private var downloadURL:URLRequest;
private var file:FileReference;
public function download(fileId:String, fileName:String){
var fileName:String = scriptFileName;
downloadURL = new URLRequest();
downloadURL.url = Globals.serverrPrefix2 + "/download";
var vars : URLVariables = enw URLVariables();
vars.id = fileId;
downloadURL.method = URLRequestMethod.POST;
downloadURL.data = vars;
file = enw FileReference();
configureListeners(file);
file.download(downloadURL, fileName);
}
private function configureListeners(dispatcher:IEventDispatcher):void{
dispatcher.addEventListener(Event.CANCEL, cancelHandler);
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(Event.SELECT, selectHandler);
}
this it my code server :
@RequestMapping(value="/download", method={RequestMethod.GET, RequestMethod.POST})
public void Download(@RequestParam(defaultValue="")String id, Model model, HttpServletResponse response) throws Exception {
String orignlFileNm = "";
String filePath = null;
Map<String,Object> p = new HashMap<String,Object>();
p.put("id", id);
Map<String,Object> retMap = new HashMap<String,Object>();
retMap = arcdao.getAttachmentInfo(p).get(0);
filePath = String.valueOf(retMap.get("file_path"));
orignlFileNm = String.valueOf(retMap.get("file_name"));
String destFPath = ConfigReader.getProperty("data.path");
destFPath = destFPath.replace("\\", "/")+ File.separator + filePath;;
File uFile = new File(destFPath);
int fSize = (int) uFile.length();
if (fSize >= 0) {
String mimetype = "application/x-msdownload";
response.setContentType(mimetype);
setDisposition(orignlFileNm, request, response);
response.setContentLength(fSize);
BufferedInputStream in = null;
BufferedOutputStream out = null;
try{
in = new BufferedInputStream(new FileInputStream(uFile));
out = new BufferedOutputStream(response.getOutputStream());
FileCopyUtils.copy(in, out);
out.flush();
}catch (Exception ex) {
logger.debug("IGNORED: " + ex.getMessage());
} finally {
if (in != null) {
try{
in.close();
}catch(Exception ignore){
logger.debug("IGNORED: " + ignore.getMessage());
}
}
if (out != null) {
try{
out.close();
}catch(Exception ignore){
logger.debug("IGNORED: " + ignore.getMessage());
}
}
}
}
