Skip to content

Commit 9370e22

Browse files
author
Jason Maurer
committed
Option to specify https for Parse.File
1 parent 0b3f7ad commit 9370e22

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/ParseFile.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,16 @@ export default class ParseFile {
134134
* Gets the url of the file. It is only available after you save the file or
135135
* after you get the file from a Parse.Object.
136136
* @method url
137+
* @param {Object} options An object to specify url options
137138
* @return {String}
138139
*/
139-
url(): ?string {
140-
return this._url;
140+
url(options?: { secure?: boolean }): ?string {
141+
options = options || {};
142+
if (options.secure) {
143+
return this._url.replace(/^http:\/\//i, 'https://');
144+
} else {
145+
return this._url;
146+
}
141147
}
142148

143149
/**

src/__tests__/ParseFile-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ describe('ParseFile', () => {
7878
}).toThrow('Cannot create a Parse.File with that data.');
7979
});
8080

81+
it('returns secure url when specified', () => {
82+
var file = new ParseFile('parse.txt', { base64: 'ParseA==' });
83+
file.save().then(function(result) {
84+
expect(result).toBe(file);
85+
expect(result.url({ secure: true }))
86+
.toBe('https://files.parsetfss.com/a/parse.txt');
87+
});
88+
});
89+
8190
it('updates fields when saved', () => {
8291
var file = new ParseFile('parse.txt', { base64: 'ParseA==' });
8392
expect(file.name()).toBe('parse.txt');

0 commit comments

Comments
 (0)