@@ -23,6 +23,13 @@ @implementation VydiaRNFileUploader
23
23
static RCTEventEmitter* staticEventEmitter = nil ;
24
24
static NSString *BACKGROUND_SESSION_ID = @" VydiaRNFileUploader" ;
25
25
NSURLSession *_urlSession = nil ;
26
+ NSMutableDictionary *_responsesData = nil ;
27
+
28
+ +(void )initialize {
29
+ if (!_responsesData) {
30
+ _responsesData = [NSMutableDictionary dictionary ];
31
+ }
32
+ }
26
33
27
34
-(id ) init {
28
35
self = [super init ];
@@ -158,6 +165,17 @@ - (void)URLSession:(NSURLSession *)session
158
165
if (response != nil )
159
166
{
160
167
[data setObject: [NSNumber numberWithInteger: response.statusCode] forKey: @" responseCode" ];
168
+
169
+ // Add data that was collected earlier by the didReceiveData method
170
+ NSMutableData *responseData = _responsesData[@(task.taskIdentifier)];
171
+ if (responseData) {
172
+ NSString *response = [[NSString alloc ] initWithData: responseData encoding: NSUTF8StringEncoding];
173
+ [data setObject: response forKey: @" responseBody" ];
174
+ } else {
175
+ [data setObject: [NSNull null ] forKey: @" responseBody" ];
176
+ }
177
+ [_responsesData removeObjectForKey: @(task.taskIdentifier)];
178
+
161
179
}
162
180
163
181
if (error == nil )
@@ -185,4 +203,15 @@ - (void)URLSession:(NSURLSession *)session
185
203
[self _sendEventWithName: @" RNFileUploader-progress" body: @{ @" id" : task.taskDescription , @" progress" : [NSNumber numberWithFloat: progress] }];
186
204
}
187
205
206
+ - (void )URLSession : (NSURLSession *)session dataTask : (NSURLSessionDataTask *)dataTask didReceiveData : (NSData *)data {
207
+ // Hold returned data so it can be picked up by the didCompleteWithError method later
208
+ NSMutableData *responseData = _responsesData[@(dataTask.taskIdentifier)];
209
+ if (!responseData) {
210
+ responseData = [NSMutableData dataWithData: data];
211
+ _responsesData[@(dataTask.taskIdentifier)] = responseData;
212
+ } else {
213
+ [responseData appendData: data];
214
+ }
215
+ }
216
+
188
217
@end
0 commit comments