Open d-blum opened 3 years ago
I have to look for a way to implement chunked file upload, as there is a limit in the rest API that limits max file upload size in a unique request.
@d-blum I've added a uploadBigFiles implementing a chunked file upload that may allow to upload files up to 2Gb to Sharepoint Online. Not yet implemented in the On Premises version. Notice that the group id of the artifact has also changed as i am planning to generate releases to maven central repository and the change was needed as if not i had to buy a domain. I tested it with a 200Mb file and the upload is working.
An example call to the method could be this
int chunkSize = 2048;
JSONObject result = client.uploadBigFile("YourLibraryOrfFolderToUploadWithoutSitePreffix",
(Resource) new FileSystemResource(new File("/PATHTOYOURFILE)), metadata, chunkSize);
THe dir (first param) dont include de sites/..., only the path to the list or folder from the site. metadata works as it worked before, with a json object with metadata to set to the document. chunkSize is an int with the size of each chunk uploaded to the server.
Let me know if you have any issue with the solution to be able to close this issue. Thanks
@kikovalle Unfortunately the new method does not work for me. I'm getting 404 NOT_FOUND. Below is the code I'm using:
client.uploadBigFile(pathToParentfolder, resource, new JSONObject("{}"), 2048);
The log is as follows: 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - HTTP POST https://my.domain/sites/My-Site/_api/web/GetFolderByServerRelativeUrl('/sites/My-Site/Shared%20Documents/share/sharepoint-api-java/tests/uploadTests/')/Files/add(url='this%20is%20a%20small%20file.txt',overwrite=true) 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - Accept=[text/plain, application/json, application/+json, /] 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - Writing [Byte array resource [resource loaded from byte array]] as "application/json;odata=verbose" 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - Response 200 OK 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - Reading to [java.lang.String] as "application/json;odata=verbose;charset=utf-8" 2021-12-09 09:09:14 DEBUG PLGSharepointClientOnline:418 - Empty file created for chunked file upload 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - HTTP POST https://my.domain/sites/My-Site_api/web/getfilebyserverrelativeurl('/sites/My-Site/Shared%20Documents/share/sharepoint-api-java/tests/uploadTests/this%20is%20a%20small%20file.txt')/startupload(uploadId=guid'123a123c-cc3e-49eb-b56d-720291074444') 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - Accept=[text/plain, application/json, application/+json, /] 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - Writing [[B@df4b72] as "application/octet-stream" 2021-12-09 09:09:14 DEBUG StreamRestTemplate:147 - Response 404 NOT_FOUND
In your project I've discovered the ChunkFileUploader. With the ChunkFileUploader I'm not facing an error 404 NOT_FOUND and the upload works as expected. The code for this approach is:
client.createChunkFileUploader().uploadFile(pathToParentfolder, resource, 5 * 1024 * 1024)
As there is a workaround that works for me I'm good with closing the issue.
I have an idea about the cause of the error, let me upload and update as i also detected a bug in last release. Hopefully this afternoon ill be able to commit the fix.
Bugfix released with 1.0.4 version. Please let me know if the 404 error is solved for you. Thank you
I'm still getting the same error with version 1.0.4
I've just released 1.0.5 version i hope will solve the issue. Let me know if it is solved, as i see in the exception it was related to the folder name and not to the upload logic itself.
Unfortunately it still does not work in version 1.0.5
I'm having this problem with 1.0.8 version. Uploading small files are fine, but uploading big file with uploadBigFile method returns 404 FILE NOT FOUND
Hey, thanks for the great api! Listing files, downloading files or uploading small files works fine but I'm facing issue with larger files. 200 MB works fine, but the upload with 410 MB fails with with error message 400 Bad Request
I don't think it's a timeout as the response is returned after only 18 seconds.
Am I missing something? Maybe a property in the header? I am grateful for all answers. Thanks in advance.
Below you can find the full stacktrace: