@@ -344,6 +344,48 @@ - (void)testPutFile {
344
344
[self waitForExpectations ];
345
345
}
346
346
347
+ - (void )testPutFileWithMetadata {
348
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutFileWithMetaData" ];
349
+
350
+ FIRStorageReference *ref =
351
+ [self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutFile" ];
352
+
353
+ NSData *data = [@" Hello World" dataUsingEncoding: NSUTF8StringEncoding];
354
+ NSURL *tmpDirURL = [NSURL fileURLWithPath: NSTemporaryDirectory ()];
355
+ NSURL *fileURL =
356
+ [[tmpDirURL URLByAppendingPathComponent: @" hello" ] URLByAppendingPathExtension: @" txt" ];
357
+ [data writeToURL: fileURL atomically: YES ];
358
+
359
+ FIRStorageMetadata *putMetadata = [[FIRStorageMetadata alloc ] init ];
360
+ putMetadata.contentType = @" text/plain" ;
361
+
362
+ FIRStorageUploadTask *task = [ref putFile: fileURL
363
+ metadata: putMetadata
364
+ completion: ^(FIRStorageMetadata *metadata, NSError *error) {
365
+ XCTAssertNotNil (metadata, " Metadata should not be nil" );
366
+ XCTAssertNil (error, " Error should be nil" );
367
+ }];
368
+
369
+ __block long uploadedBytes = -1 ;
370
+
371
+ [task observeStatus: FIRStorageTaskStatusSuccess
372
+ handler: ^(FIRStorageTaskSnapshot *snapshot) {
373
+ XCTAssertEqualObjects ([snapshot description ], @" <State: Success>" );
374
+ [expectation fulfill ];
375
+ }];
376
+
377
+ [task observeStatus: FIRStorageTaskStatusProgress
378
+ handler: ^(FIRStorageTaskSnapshot *_Nonnull snapshot) {
379
+ XCTAssertTrue ([[snapshot description ] containsString: @" State: Progress" ] ||
380
+ [[snapshot description ] containsString: @" State: Resume" ]);
381
+ NSProgress *progress = snapshot.progress ;
382
+ XCTAssertGreaterThanOrEqual (progress.completedUnitCount , uploadedBytes);
383
+ uploadedBytes = (long )progress.completedUnitCount ;
384
+ }];
385
+
386
+ [self waitForExpectations ];
387
+ }
388
+
347
389
- (void )testPutFileWithSpecialCharacters {
348
390
XCTestExpectation *expectation =
349
391
[self expectationWithDescription: @" testPutFileWithSpecialCharacters" ];
0 commit comments