Skip to main content

I am working on a PowerShell script to automate archiving files that are 5GB each. I am working directly with the API in PowerShell since BoxCLI does not utilize chunked uploads. 

When running the “POST Upload Part of a File” command for the final chunk of a file, I am getting an error that the content-range is invalid. The final part of the file is not the same length as the rest of the parts, and the documentation states that is an allowed exception. 

All initial parts upload without error, and return the expected values for the upload. When I run the final part using a content-range header value of “83886080-95925607/95925607” I get the following error:

{
"code": "range_out_of_bounds",
"message": "Part with offset 83886080 and size 12039528 exceeds limits of file size 95925607",
"request_id": "8642639592d5d19e401d2d252ba83641"
}

It looks like the API is ignoring the higher bound value provided in the content-range and using the higher bound that would be set if using the full part_size value defined when creating the session. 

 

Is there an additional parameter that needs to be passed in with the final part to let the API know the size of this part may not match the predetermined part size?

Hi @ryanp, thanks for bringing this up.

It’s likely there’s a minor error in math here that is impacting the last chunk. For the final part of your file upload, you can try adjusting the content-range header value to match the actual size of the final part.

  • For example:
    If the final part has an offset of 83886080 and a size of 12039528, you can use a content-range header value like this: "83886080-95925507/95925607". This ensures that the API recognizes the correct size for the final part.

If the adjustment doesn't work, there might be an additional parameter that needs to be passed in with the final part to inform the API about any deviations from the predetermined part size.

By the way, regarding your original concern, BoxCLI supports chunked uploads. It recognizes the size of the file and then performs a multiput upload if needed, much like the webapp or Box Drive. You can also use an SDK, which will do the chunking for you.

If you want to proceed with the manual chunked upload process and are still running into issues, we would need to investigate further. With that, please submit a support ticket here.

Looking forward to achieving excellent results! 🙌


@JeyBueno Box I provide the correct content-range value for the final part and the error message that it spits out does not recognize that I put in a value that matches the file size. I have tried this with the file size variable being equal to the number of bytes for the file, 1 more byte, and 1 less byte. All parts upload except for the last file. I have had a support ticket open for over 2 weeks and have not made any progress which is why I came here to see if anyone else has experienced this issue. 

Session details are below along with the content range values that are being passed in. 

  • Total Parts: 6
  • Part Size: 16777216
  • Part 1: 0-16777215/95925607
  • Part 2: 16777216-33554431/95925607
  • Part 3: 33554432-50331647/95925607
  • Part 4: 50331648-67108863/95925607
  • Part 5: 67108864-83886079/95925607
  • Part 6: 83886080-95925607/95925607

The final part is using the actual file size for the max value but the error returned from the API still says "Part with offset 83886080 and size 12039528 exceeds limits of file size 95925607.” It almost seems like the API doesn’t know that I am uploading the final part and assumes what I passed in for a content range is not correct and adjusts to match the part size defined for the session. 

 

I did find out that the BoxCLI supports chunked uploads (after getting wrong information from support the first time). However, the requirements for installing the tool and keeping a file with creds on the device, make the BoxCLI not suitable for automation at scale. SDKs are also not an option since I am working in PowerShell so these scripts can be run from our management tool on any device in the environment. 


Dear @ryanp, I appreciate the information and your continued patience to resolve the issue. I can confirm that our dedicated Product Support is investigating this. I’ve raised this information on the same ticket # that you have submitted and we’ll reach out to you from there to address your concerns. Thank you so much! 🙂


Reply