@@ -140,52 +140,14 @@ public String url() {
140
140
private Set <Task <?>.TaskCompletionSource > currentTasks = Collections .synchronizedSet (
141
141
new HashSet <Task <?>.TaskCompletionSource >());
142
142
143
- /**
144
- * Creates a new file from a file pointer, file name, and content type. Content type will be used
145
- * instead of auto-detection by file extension.
146
- *
147
- * @param name
148
- * The file's name, ideally with extension. The file name must begin with an alphanumeric
149
- * character, and consist of alphanumeric characters, periods, spaces, underscores, or
150
- * dashes.
151
- * @param file
152
- * The file.
153
- * @param contentType
154
- * The file's content type.
155
- */
156
- public ParseFile (String name , File file , String contentType ) {
157
- this (new State .Builder ().name (name ).mimeType (contentType ).build ());
158
- if (file .length () > MAX_FILE_SIZE ) {
159
- throw new IllegalArgumentException (String .format ("ParseFile must be less than %d bytes" ,
160
- MAX_FILE_SIZE ));
161
- }
162
- this .file = file ;
163
- }
164
-
165
143
/**
166
144
* Creates a new file from a file pointer.
167
145
*
168
146
* @param file
169
147
* The file.
170
148
*/
171
149
public ParseFile (File file ) {
172
- this (null , file , null );
173
- }
174
-
175
- /**
176
- * Creates a new file from a file pointer and a name. Giving a name with a proper file extension
177
- * (e.g. ".png") is ideal because it allows Parse to deduce the content type of the file and set
178
- * appropriate HTTP headers when it is fetched.
179
- *
180
- * @param name
181
- * The file's name, ideally with extension. The file name must begin with an alphanumeric
182
- * character, and consist of alphanumeric characters, periods, spaces, underscores, or
183
- * dashes.
184
- * @param file
185
- * The file.
186
- */
187
- public ParseFile (String name , File file ) {
188
- this (name , file , null );
150
+ this (file , null );
189
151
}
190
152
191
153
/**
@@ -198,7 +160,12 @@ public ParseFile(String name, File file) {
198
160
* The file's content type.
199
161
*/
200
162
public ParseFile (File file , String contentType ) {
201
- this (null , file , contentType );
163
+ this (new State .Builder ().name (file .getName ()).mimeType (contentType ).build ());
164
+ if (file .length () > MAX_FILE_SIZE ) {
165
+ throw new IllegalArgumentException (String .format ("ParseFile must be less than %d bytes" ,
166
+ MAX_FILE_SIZE ));
167
+ }
168
+ this .file = file ;
202
169
}
203
170
204
171
/**
@@ -335,24 +302,30 @@ public Task<Void> then(Task<Void> task) throws Exception {
335
302
return Task .cancelled ();
336
303
}
337
304
338
- Task <ParseFile .State > saveTask = data != null ?
339
- getFileController ().saveAsync (
340
- state ,
341
- data ,
342
- sessionToken ,
343
- progressCallbackOnMainThread (uploadProgressCallback ),
344
- cancellationToken ) :
345
- getFileController ().saveAsync (
346
- state ,
347
- file ,
348
- sessionToken ,
349
- progressCallbackOnMainThread (uploadProgressCallback ),
350
- cancellationToken );
305
+ Task <ParseFile .State > saveTask ;
306
+ if (data != null ) {
307
+ saveTask = getFileController ().saveAsync (
308
+ state ,
309
+ data ,
310
+ sessionToken ,
311
+ progressCallbackOnMainThread (uploadProgressCallback ),
312
+ cancellationToken );
313
+ } else {
314
+ saveTask = getFileController ().saveAsync (
315
+ state ,
316
+ file ,
317
+ sessionToken ,
318
+ progressCallbackOnMainThread (uploadProgressCallback ),
319
+ cancellationToken );
320
+ }
351
321
352
322
return saveTask .onSuccessTask (new Continuation <State , Task <Void >>() {
353
323
@ Override
354
324
public Task <Void > then (Task <State > task ) throws Exception {
355
325
state = task .getResult ();
326
+ // Since we have successfully uploaded the file, we do not need to hold the file pointer
327
+ // anymore.
328
+ file = null ;
356
329
return task .makeVoid ();
357
330
}
358
331
});
0 commit comments