Skip to content

Commit b02ea6a

Browse files
authored
fix(uploader): send content_modified_at with plain upload (#702)
1 parent 9ac5592 commit b02ea6a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/api/uploads/PlainUpload.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import noop from 'lodash/noop';
88
import BaseUpload from './BaseUpload';
99
import { digest } from '../../util/webcrypto';
10+
import { getFileLastModifiedAsISONoMSIfPossible } from '../../util/uploads';
1011

1112
const CONTENT_MD5_HEADER = 'Content-MD5';
1213

@@ -75,6 +76,7 @@ class PlainUpload extends BaseUpload {
7576
const attributes = JSON.stringify({
7677
name: this.fileName,
7778
parent: { id: this.folderId },
79+
content_modified_at: getFileLastModifiedAsISONoMSIfPossible(this.file),
7880
});
7981

8082
const options = {

src/api/uploads/__tests__/PlainUpload-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PlainUpload from '../PlainUpload';
22
import * as crypto from '../../../util/webcrypto';
3+
import * as uploads from '../../../util/uploads';
34

45
let upload;
56

@@ -124,6 +125,15 @@ describe('api/uploads/PlainUpload', () => {
124125
});
125126

126127
describe('preflightSuccessHandler', () => {
128+
const MODIFIED_AT = 123456;
129+
beforeEach(() => {
130+
jest.spyOn(uploads, 'getFileLastModifiedAsISONoMSIfPossible').mockReturnValue(MODIFIED_AT);
131+
});
132+
133+
afterEach(() => {
134+
jest.restoreAllMocks();
135+
});
136+
127137
test('should not do anything if API is destroyed', () => {
128138
upload.isDestroyed = jest.fn().mockReturnValueOnce(true);
129139
upload.xhr = {
@@ -149,7 +159,7 @@ describe('api/uploads/PlainUpload', () => {
149159
expect(upload.xhr.uploadFile).toHaveBeenCalledWith({
150160
url: `${upload.uploadHost}/api/2.0/files/content`,
151161
data: {
152-
attributes: '{"name":"warlock-152340","parent":{"id":"123"}}',
162+
attributes: `{"name":"warlock-152340","parent":{"id":"123"},"content_modified_at":${MODIFIED_AT}}`,
153163
file: upload.file,
154164
},
155165
headers: {

0 commit comments

Comments
 (0)