Merge pull request #579 from ParsePlatform/nlutsenko.files.contentType
Allow uploading files without Content-Type.
This commit is contained in:
@@ -10,7 +10,8 @@ for (var i = 0; i < str.length; i++) {
|
||||
}
|
||||
|
||||
describe('Parse.File testing', () => {
|
||||
it('works with REST API', done => {
|
||||
describe('creating files', () => {
|
||||
it('works with Content-Type', done => {
|
||||
var headers = {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'X-Parse-Application-Id': 'test',
|
||||
@@ -33,6 +34,29 @@ describe('Parse.File testing', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('works without Content-Type', done => {
|
||||
var headers = {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest'
|
||||
};
|
||||
request.post({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/files/file.txt',
|
||||
body: 'argle bargle',
|
||||
}, (error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
var b = JSON.parse(body);
|
||||
expect(b.name).toMatch(/_file.txt$/);
|
||||
expect(b.url).toMatch(/^http:\/\/localhost:8378\/1\/files\/test\/.*file.txt$/);
|
||||
request.get(b.url, (error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
expect(body).toEqual('argle bargle');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('supports REST end-to-end file create, read, delete, read', done => {
|
||||
var headers = {
|
||||
'Content-Type': 'image/jpeg',
|
||||
|
||||
@@ -19,7 +19,7 @@ export class FilesRouter {
|
||||
|
||||
router.post('/files/:filename',
|
||||
Middlewares.allowCrossDomain,
|
||||
BodyParser.raw({type: '*/*', limit: '20mb'}),
|
||||
BodyParser.raw({type: () => { return true; }, limit: '20mb'}), // Allow uploads without Content-Type, or with any Content-Type.
|
||||
Middlewares.handleParseHeaders,
|
||||
this.createHandler
|
||||
);
|
||||
@@ -33,18 +33,18 @@ export class FilesRouter {
|
||||
return router;
|
||||
}
|
||||
|
||||
getHandler(req, res, next) {
|
||||
getHandler(req, res) {
|
||||
const config = new Config(req.params.appId);
|
||||
const filesController = config.filesController;
|
||||
const filename = req.params.filename;
|
||||
filesController.getFileData(config, filename).then((data) => {
|
||||
res.status(200);
|
||||
var contentType = mime.lookup(filename);
|
||||
res.set('Content-type', contentType);
|
||||
res.set('Content-Type', contentType);
|
||||
res.end(data);
|
||||
}).catch((error) => {
|
||||
}).catch(() => {
|
||||
res.status(404);
|
||||
res.set('Content-type', 'text/plain');
|
||||
res.set('Content-Type', 'text/plain');
|
||||
res.end('File not found.');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user