Back out D2098670: Allow uploading a native file (e.g. photo) via XMLHttpRequest
This commit is contained in:
parent
cfa4b13472
commit
3269af227f
|
@ -23,6 +23,4 @@
|
||||||
+ (void)loadImageWithTag:(NSString *)tag
|
+ (void)loadImageWithTag:(NSString *)tag
|
||||||
callback:(void (^)(NSError *error, id /* UIImage or CAAnimation */ image))callback;
|
callback:(void (^)(NSError *error, id /* UIImage or CAAnimation */ image))callback;
|
||||||
|
|
||||||
+ (BOOL)isSystemImageURI:(NSString *)uri;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -154,11 +154,4 @@ static void RCTDispatchCallbackOnMainQueue(void (^callback)(NSError *, id), NSEr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL)isSystemImageURI:(NSString *)uri
|
|
||||||
{
|
|
||||||
return uri != nil && (
|
|
||||||
[uri hasPrefix:@"assets-library"] ||
|
|
||||||
[uri hasPrefix:@"ph://"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#import "RCTConvert.h"
|
#import "RCTConvert.h"
|
||||||
#import "RCTLog.h"
|
#import "RCTLog.h"
|
||||||
#import "RCTUtils.h"
|
#import "RCTUtils.h"
|
||||||
#import "RCTImageLoader.h"
|
|
||||||
|
|
||||||
@implementation RCTDataManager
|
@implementation RCTDataManager
|
||||||
|
|
||||||
|
@ -35,43 +34,8 @@ RCT_EXPORT_METHOD(queryData:(NSString *)queryType
|
||||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
||||||
request.HTTPMethod = [RCTConvert NSString:query[@"method"]] ?: @"GET";
|
request.HTTPMethod = [RCTConvert NSString:query[@"method"]] ?: @"GET";
|
||||||
request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]];
|
request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]];
|
||||||
|
request.HTTPBody = [RCTConvert NSData:query[@"data"]];
|
||||||
|
|
||||||
if (query[@"data"] != [NSNull null]) {
|
|
||||||
NSDictionary *data = [RCTConvert NSDictionary:query[@"data"]];
|
|
||||||
NSData *body = [RCTConvert NSData:data[@"string"]];
|
|
||||||
if (body != nil) {
|
|
||||||
request.HTTPBody = body;
|
|
||||||
[RCTDataManager sendRequest:request responseSender:responseSender];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NSString *uri = [RCTConvert NSString:data[@"uri"]];
|
|
||||||
if (uri != nil) {
|
|
||||||
if ([RCTImageLoader isSystemImageURI:uri]) {
|
|
||||||
[RCTImageLoader loadImageWithTag:(NSString *)uri callback:^(NSError *error, UIImage *image) {
|
|
||||||
if (error) {
|
|
||||||
RCTLogError(@"Error loading image URI: %@", error);
|
|
||||||
// We should really circle back to JS here and notify an error/abort on the request.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
|
|
||||||
request.HTTPBody = imageData;
|
|
||||||
[RCTDataManager sendRequest:request responseSender:responseSender];
|
|
||||||
}];
|
|
||||||
} else {
|
|
||||||
RCTLogError(@"Cannot resolve URI: %@", uri);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// There was no data payload, or we couldn't understand it.
|
|
||||||
[RCTDataManager sendRequest:request responseSender:responseSender];
|
|
||||||
} else {
|
|
||||||
RCTLogError(@"unsupported query type %@", queryType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (void)sendRequest:(NSURLRequest *)request responseSender:(RCTResponseSenderBlock)responseSender {
|
|
||||||
// Build data task
|
// Build data task
|
||||||
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) {
|
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) {
|
||||||
|
|
||||||
|
@ -107,6 +71,11 @@ RCT_EXPORT_METHOD(queryData:(NSString *)queryType
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[task resume];
|
[task resume];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
RCTLogError(@"unsupported query type %@", queryType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -209,7 +209,6 @@
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||||
"$(SRCROOT)/../../React/**",
|
"$(SRCROOT)/../../React/**",
|
||||||
"$(SRCROOT)/../Image/**",
|
|
||||||
);
|
);
|
||||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||||
OTHER_LDFLAGS = "-ObjC";
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
|
@ -227,7 +226,6 @@
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||||
"$(SRCROOT)/../../React/**",
|
"$(SRCROOT)/../../React/**",
|
||||||
"$(SRCROOT)/../Image/**",
|
|
||||||
);
|
);
|
||||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||||
OTHER_LDFLAGS = "-ObjC";
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
|
|
|
@ -20,16 +20,13 @@ var XMLHttpRequestBase = require('XMLHttpRequestBase');
|
||||||
class XMLHttpRequest extends XMLHttpRequestBase {
|
class XMLHttpRequest extends XMLHttpRequestBase {
|
||||||
|
|
||||||
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
|
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
|
||||||
if (typeof data === 'string') {
|
|
||||||
data = {string: data};
|
|
||||||
}
|
|
||||||
RCTDataManager.queryData(
|
RCTDataManager.queryData(
|
||||||
'http',
|
'http',
|
||||||
{
|
{
|
||||||
method,
|
method: method,
|
||||||
url,
|
url: url,
|
||||||
data,
|
data: data,
|
||||||
headers,
|
headers: headers,
|
||||||
},
|
},
|
||||||
// TODO: Do we need this? is it used anywhere?
|
// TODO: Do we need this? is it used anywhere?
|
||||||
'h' + crc32(method + '|' + url + '|' + data),
|
'h' + crc32(method + '|' + url + '|' + data),
|
||||||
|
|
Loading…
Reference in New Issue