Closed solepixel closed 4 years ago
Just a side note on this, I made a duplicate of the site running PHP v7.0.33 and was able to successfully send the 114MB file to OneDrive, so not really sure where the problem lies. The site was running PHP 7.3.11 and hosted at DreamHost.
Thanks for your report @solepixel, I am currently on vacation, I will look into that in January. Thanks.
@krizalys Thanks for checking-in! I'll let you know if I find anything new in the meantime.
@solepixel The API server reported a URL with some GET parameters encoded strangely (eg. wrapped in single quotes), please can you share the code which is causing this error?
@krizalys Sorry about the delayed feedback on this. This is the code being used:
$file_size = filesize( $file );
$file_info = pathinfo( $file );
$file_ext = $file_info['extension'];
if ( 'zip' === $file_ext ) {
$mime_type = 'application/zip';
} elseif ( 'php' === $file_ext ) {
$mime_type = 'application/x-httpd-php';
} else {
$mime_type = '';
}
$folder = self::get_drive_item( false, $folder_id );
if ( ! is_object( $folder ) ) {
self::error( __( 'There was an error uploading file to OneDrive.', 'LION' ) );
return false;
}
try {
$args = array();
if ( $mime_type ) {
$args['contentType'] = $mime_type;
}
// Returns UploadSessionProxy object.
$upload = $folder->startUpload( basename( $file ), fopen( $file, 'rb' ), $args );
} catch ( \Exception $e ) {
self::error( __( 'Error', 'LION' ) . ' #201910150859: ' . __( 'Could not initiate upload for', 'LION' ) . ' `' . basename( $file ) . '`. ' . __( 'Details', 'LION' ) . ': ' . $e->getMessage() );
return false;
}
try {
// Potentially returns DriveItemProxy object.
$status = $upload->complete();
} catch ( \Exception $e ) {
self::error( __( 'Error', 'LION' ) . ' #201910161524: ' . __( 'OneDrive upload failed for', 'LION' ) . ' `' . basename( $file ) . '`. ' . __( 'Details', 'LION' ) . ': ' . $e->getMessage() );
return false;
}
@solepixel Did you find a solution for this problem? I am experiencing same problem while uploading 12MB CSV file.
I have changed fopen parameter from "rb" to "r". It worked for me.
@solepixel @mgardener I was able to successfully upload a 150 MB file using the code above + missing functions.
Is it still happening? If not, and since it's a 5XX error, I'll suggest that there is indeed a possiblity that the OneDrive service/your network was having issues at the time you experienced this.
Please feel free to reopen + PHP version, full code, upload file if you can reproduce this.
I have applied the change @mgardener posted and I haven't heard any negative feedback, so I also am assuming that resolved the issue. Thanks @krizalys!
So, in a different ticket, I got some sample code for handling file uploads. One of our users is experiencing issues uploading a 114MB file, with the error log reporting:
Any idea what could be the cause of this? 114MB hardly seems large enough to be causing the issue, although smaller files have successfully uploaded. Could there be server limitations? Where do I need to look to pinpoint this problem?
Somewhat of a side question, once
startUpload()
is called, is there a way to stop/cancel the transfer?