Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ParseFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ const DefaultController = {

const headers: Record<string, string> = {
'X-Parse-Application-ID': CoreManager.get('APPLICATION_ID'),
'X-Parse-Upload-Mode': 'stream',
};
headers['Content-Type'] = (source.type || 'application/octet-stream').replace(/[\r\n]/g, '');
const jsKey = CoreManager.get('JAVASCRIPT_KEY');
Expand Down
26 changes: 26 additions & 0 deletions src/__tests__/ParseFile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ describe('FileController', () => {
'Content-Type': 'application/octet-stream',
'X-Parse-Application-ID': 'testAppId',
'X-Parse-JavaScript-Key': 'testJsKey',
'X-Parse-Upload-Mode': 'stream',
}),
expect.any(Object)
);
Expand Down Expand Up @@ -966,11 +967,34 @@ describe('FileController', () => {
expect.objectContaining({
'Content-Type': 'text/plain',
'X-Parse-Application-ID': 'testAppId',
'X-Parse-Upload-Mode': 'stream',
}),
expect.any(Object)
);
});

it('base64 uploads do not include X-Parse-Upload-Mode header', async () => {
const request = jest.fn().mockResolvedValue({
name: 'parse.txt',
url: 'https://files.example.com/a/parse.txt',
});
const ajax = jest.fn();
CoreManager.setRESTController({ request, ajax });
CoreManager.set('APPLICATION_ID', 'testAppId');

const file = new ParseFile('parse.txt', [61, 170, 236, 120]);
await file.save();

expect(request).toHaveBeenCalledWith(
'POST',
'files/parse.txt',
expect.objectContaining({ base64: expect.any(String) }),
expect.any(Object)
);
// Binary path (which sets X-Parse-Upload-Mode) should not be taken
expect(ajax).not.toHaveBeenCalled();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

it('saveBinary includes session token from options', async () => {
const ajax = jest.fn().mockResolvedValue({
response: { name: 'parse.txt', url: 'https://files.example.com/a/parse.txt' },
Expand Down Expand Up @@ -1225,6 +1249,8 @@ describe('FileController', () => {
// Web ReadableStream (no .pipe/.read) should be passed directly as body
const body = ajax.mock.calls[0][2];
expect(body).toBe(stream);
const headers = ajax.mock.calls[0][3];
expect(headers['X-Parse-Upload-Mode']).toBe('stream');
} finally {
globalThis.ReadableStream = origReadableStream;
}
Expand Down