Skip to main content
Question

BOX File content API range header.

  • May 22, 2025
  • 2 replies
  • 32 views

Forum|alt.badge.img

I'm trying to extract some portion of the file using file/{:id}/content API with range attribute in the header, but it is giving me CORS error. 

2 replies

Forum|alt.badge.img

Hi there,

This information should give you more details on how to address the CORS issue, which I'm guessing is related to making the request from JavaScript?

- Jon


Forum|alt.badge.img

Hi Jon,

Yeah, I was trying to make a range request in javascript.

I figured out after some trial and error that the BOX API was expecting range: bytes={start}-{end} in the request header. But the API reference documentation did not specify that it requires bytes= in the range attribute. Below is the working code, I was not including bytes= earlier and that was causing the issue.

const response = await fetch(`https://api.box.com/2.0/files/${id}/content`, {
        headers: {
            "Authorization": `Bearer ${access_token}`,
            'range': `bytes=${start}-${end}`
        }, 
    });
 
Thanks,
Bhaumik