-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow large Parse File uploads #9286
Open
dalyaidan1
wants to merge
27
commits into
parse-community:alpha
Choose a base branch
from
dalyaidan1:parse-file-large-upload
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
734d85e
feat: adjust the router for large buffers
dalyaidan1 088c669
feat: adjust adapter for large blobs
dalyaidan1 3385d2f
test: test file uploads
dalyaidan1 0a2c904
fix: don't depend on axios
dalyaidan1 d2c89af
feat: clean up files
dalyaidan1 216c078
fix: file default data and adapter comment
dalyaidan1 a559453
test: split test and move to better file
dalyaidan1 39face2
fix: remove unwanted line
dalyaidan1 aedd984
fix typo
mtrezza c814b30
Merge branch 'alpha' into parse-file-large-upload
mtrezza 0cf1391
fix: remove unneeded server reconfigure
dalyaidan1 92b5ec5
fix: actually upload the full files
dalyaidan1 5bd46b6
fix: encryption chunking
dalyaidan1 01cce43
test: adjust to test blobs too
dalyaidan1 f296828
use pipes
dalyaidan1 73bbdb0
fix: remove web readable
dalyaidan1 d43a8ad
fix: test errors and clean up pipes
dalyaidan1 f817c20
fix: remove unused dep
dalyaidan1 aabae8b
fix: comment typo
dalyaidan1 07098f9
feat: ternary iv
dalyaidan1 f09037f
Merge branch 'alpha' into parse-file-large-upload
mtrezza 5c298b3
remove Blob avail check
mtrezza e276df3
remove blob check
mtrezza fad46b3
Merge branch 'alpha' into parse-file-large-upload
mtrezza 18157be
change file router to only mongo
dalyaidan1 a87a452
Merge branch 'alpha' into parse-file-large-upload
mtrezza 7e23668
Merge branch 'alpha' into parse-file-large-upload
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
describe('FilesRouter', () => { | ||
describe('File Uploads', () => { | ||
const V8_STRING_LIMIT_BYTES = 536_870_912; | ||
|
||
let server; | ||
|
||
beforeAll(async () => { | ||
server = await reconfigureServer({ | ||
maxUploadSize: '1GB', | ||
port: 8384, | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
// clean up the server for resuse | ||
if (server && server.close) { | ||
await new Promise((resolve, reject) => { | ||
server.close(err => { | ||
if (err) return reject(err); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
/** | ||
* Quick helper function to upload the file to the server via the REST API | ||
* We do this because creating a Parse.File object with a file over 512MB | ||
* will try to use the Web API FileReader API, which will fail the test | ||
* | ||
* @param {string} fileName the name of the file | ||
* @param {string} filePath the path to the file locally | ||
* @returns | ||
*/ | ||
const postFile = async (fileName, filePath) => { | ||
const url = `${Parse.serverURL}/files/${fileName}`; | ||
const headers = { | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-Master-Key': Parse.masterKey, | ||
'Content-Type': 'multipart/form-data', | ||
}; | ||
|
||
// Create a FormData object to send the file | ||
const formData = new FormData(); | ||
formData.append('file', fs.createReadStream(filePath)); | ||
|
||
// Send the request | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers, | ||
body: formData, | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
|
||
it('should allow Parse.File uploads under 512MB', async done => { | ||
const filePath = path.join(__dirname, 'file.txt'); | ||
fs.writeFileSync(filePath, Buffer.alloc(1024 * 1024)); | ||
|
||
const response = await postFile('file.txt', filePath); | ||
expect(response.ok).toBe(true); | ||
|
||
fs.unlinkSync(filePath); | ||
done(); | ||
}); | ||
|
||
it('should allow Parse.File uploads exactly 512MB', async done => { | ||
const filePath = path.join(__dirname, 'file.txt'); | ||
fs.writeFileSync(filePath, Buffer.alloc(V8_STRING_LIMIT_BYTES)); | ||
|
||
const response = await postFile('file.txt', filePath); | ||
expect(response.ok).toBe(true); | ||
|
||
fs.unlinkSync(filePath); | ||
done(); | ||
}); | ||
|
||
it('should allow Parse.File uploads over 512MB', async done => { | ||
const filePath = path.join(__dirname, 'file.txt'); | ||
fs.writeFileSync(filePath, Buffer.alloc(V8_STRING_LIMIT_BYTES + 50 * 1024 * 1024)); | ||
|
||
const response = await postFile('file.txt', filePath); | ||
expect(response.ok).toBe(true); | ||
|
||
fs.unlinkSync(filePath); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be enough to just call
await reconfigureServer()
to init the server with the default config?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your right. Missed that, new to testing here.