Use More PhoneGap/Cordova 2.0.0 - Create iOS/Android Application Using 8th File API [No.5] Sample, Cannot be Upload

Asked 2 years ago, Updated 2 years ago, 108 views

http://gihyo.jp/dev/serial/01/phonegap2/0008?page=2
Based on the above code, we are currently creating an iPad upload application with monaca.
Current situation (partial excerpt) is as follows,
By executing uploadFile, gihyojp_logo2.png is sent to http://10.0.0.183/file/receive.php.receive.php is the same as the link above.

function uploadFile(event){
    // Create FileTransfer Object
    var fileTransfer = new FileTransfer();

    // Encode URI to upload destination
    varuri=encodeURI('http://10.0.0.183/file/receive.php');

    // Create FileUploadOptions object and specify information when sending
    var uploadOptions = new FileUploadOptions();
    uploadOptions.fileKey='file';
    uploadOptions.fileName='gihyojp_logo2.png';
    var ref = window.open('http://10.0.0.183/file/receive.php', '_blank', 'location=no');

    // Perform file upload
    fileTransfer.upload(cordova.file.documentsDirectory+'gihyojp_logo2.png',uri,uploadSuccess,uploadFail,uploadOptions);
}

function uploadSuccess(uploadResult){
    var result;

    // Parse the JSON returned from the upload destination (receive.php)
    if('Android'===device.platform){
        result=JSON.parse(uploadResult.response);
    } else{ 
        // Decode with decodeURI because iOS is an encoded string.
        result=JSON.parse(decodeURI(uploadResult.response)));
    }
    alert(result);
    if(0===result.errorCode){
        alert('File upload succeeded\nbytesSent:'+uploadResult.bytesSent+'\nresponseCode:'+uploadResult.responseCode);
    } else{
        alert('File upload failed\n'+result.message+'\nbytesSent:'+uploadResult.bytesSent+'\nresponseCode:'+uploadResult.responseCode);
    }
}

The results are

Failed to upload file      
Null        
bytesSent—2061
responseCode —200

is the case.There seems to be no result, but where is the problem?

ios monaca cordova

2022-09-29 22:10

1 Answers

I considered it, but this was a PHP configuration bug, not Monaca.
The upload was successful.


2022-09-29 22:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.