11diff --git a/node_modules/react-native-macos/Libraries/Blob/BlobManager.js b/node_modules/react-native-macos/Libraries/Blob/BlobManager.js
2- index f4c5ed3..7628f81 100644
2+ index f4c5ed3..f7afaf4 100644
33--- a/node_modules/react-native-macos/Libraries/Blob/BlobManager.js
44+++ b/node_modules/react-native-macos/Libraries/Blob/BlobManager.js
55@@ -9,7 +9,7 @@
@@ -26,3 +26,124 @@ index f4c5ed3..7628f81 100644
2626 }
2727 if (part instanceof Blob) {
2828 return {
29+ @@ -92,6 +94,7 @@ class BlobManager {
30+ }, 0);
31+
32+ NativeBlobModule.createFromParts(items, blobId);
33+ + // console.error('BlobManager thinks blob id ' + blobId + ' already exists (but it may not yet on iOS!).');
34+
35+ return BlobManager.createFromOptions({
36+ blobId,
37+ diff --git a/node_modules/react-native-macos/Libraries/Blob/RCTBlobManager.mm b/node_modules/react-native-macos/Libraries/Blob/RCTBlobManager.mm
38+ index 9d4cde7..c9e6a81 100755
39+ --- a/node_modules/react-native-macos/Libraries/Blob/RCTBlobManager.mm
40+ +++ b/node_modules/react-native-macos/Libraries/Blob/RCTBlobManager.mm
41+ @@ -95,6 +95,7 @@ RCT_EXPORT_MODULE(BlobModule)
42+ - (void)store:(NSData *)data withId:(NSString *)blobId
43+ {
44+ std::lock_guard<std::mutex> lock(_blobsMutex);
45+ + //RCTLogError(@"RCTBlobManager store inside mutex storing blob id %@", blobId);
46+ _blobs[blobId] = data;
47+ }
48+
49+ @@ -117,9 +118,13 @@ RCT_EXPORT_MODULE(BlobModule)
50+ NSData *data;
51+ {
52+ std::lock_guard<std::mutex> lock(_blobsMutex);
53+ + // FIXME Right here it seems the blob does not exist for some reason?
54+ + //RCTLogError(@"RCTBlobManager resolve inside mutex resolving blob id %@", blobId);
55+ data = _blobs[blobId];
56+ }
57+ if (!data) {
58+ + // FIXME and we return nil to handleNetworkingRequest which then crashes
59+ + //RCTLogError(@"RCTBlobManager resolve no data for blob id %@", blobId);
60+ return nil;
61+ }
62+ if (offset != 0 || (size != -1 && size != data.length)) {
63+ @@ -156,6 +161,7 @@ RCT_EXPORT_MODULE(BlobModule)
64+ - (void)remove:(NSString *)blobId
65+ {
66+ std::lock_guard<std::mutex> lock(_blobsMutex);
67+ + //RCTLogError(@"RCTBlobManager remove inside mutex removing blob id %@", blobId);
68+ [_blobs removeObjectForKey:blobId];
69+ }
70+
71+ @@ -217,15 +223,19 @@ RCT_EXPORT_METHOD(createFromParts : (NSArray<NSDictionary<NSString *, id> *> *)p
72+ }
73+ }
74+
75+ + //RCTLogError(@"RCTBlobManager createFromParts requesting store of blob id %@", blobId);
76+ dispatch_async([self executionQueue], ^{
77+ [self store:data withId:blobId];
78+ + //RCTLogError(@"RCTBlobManager createFromParts done storing blob id %@", blobId);
79+ });
80+ }
81+
82+ RCT_EXPORT_METHOD(release : (NSString *)blobId)
83+ {
84+ + //RCTLogError(@"RCTBlobManager enqueueing release of blob id %@", blobId);
85+ dispatch_async([self executionQueue], ^{
86+ [self remove:blobId];
87+ + //RCTLogError(@"RCTBlobManager done releasing blob id %@", blobId);
88+ });
89+ }
90+
91+ @@ -297,13 +307,30 @@ RCT_EXPORT_METHOD(release : (NSString *)blobId)
92+ // @lint-ignore FBOBJCUNTYPEDCOLLECTION1
93+ NSDictionary *blob = [RCTConvert NSDictionary:data[@"blob"]];
94+
95+ + // FIXME so here - we checked that data[@"blob"] was non-nil in canHandleHandleNetworkingRequest
96+ +
97+ NSString *contentType = @"application/octet-stream";
98+ NSString *blobType = [RCTConvert NSString:RCTNilIfNull(blob[@"type"])];
99+ if (blobType != nil && blobType.length > 0) {
100+ contentType = blob[@"type"];
101+ }
102+
103+ - return @{@"body" : [self resolve:blob], @"contentType" : contentType};
104+ + // FIXME but here in resolve:blob the blob isn't found somehow? comes back nil?
105+ + NSData *blobBody = nil;
106+ + NSString *blobId = nil;
107+ + for (int retries = 0; blobBody == nil && retries < 100; retries++) {
108+ + blobBody = [self resolve:blob];
109+ + if (blobBody == nil) {
110+ + if (blobId == nil) {
111+ + blobId = [RCTConvert NSString:blob[@"blobId"]];
112+ + }
113+ + //RCTLogError(@"RCTBlobManager handleNetworkingRequest nil blobBody for blob id %@", blobId);
114+ + //RCTLogError(@"RCTBlobManager handleNetworkingRequest, sleeping for blob id %@", blobId);
115+ + [NSThread sleepForTimeInterval:0.1f];
116+ + }
117+ + }
118+ +
119+ + return @{@"body" : blobBody, @"contentType" : contentType};
120+ }
121+
122+ - (BOOL)canHandleNetworkingResponse:(NSString *)responseType
123+ diff --git a/node_modules/react-native-macos/Libraries/Network/RCTNetworking.mm b/node_modules/react-native-macos/Libraries/Network/RCTNetworking.mm
124+ index 80d8c30..b68a67e 100644
125+ --- a/node_modules/react-native-macos/Libraries/Network/RCTNetworking.mm
126+ +++ b/node_modules/react-native-macos/Libraries/Network/RCTNetworking.mm
127+ @@ -417,9 +417,19 @@ RCT_EXPORT_MODULE()
128+ for (id<RCTNetworkingRequestHandler> handler in _requestHandlers) {
129+ if ([handler canHandleNetworkingRequest:query]) {
130+ // @lint-ignore FBOBJCUNTYPEDCOLLECTION1
131+ - NSDictionary *body = [handler handleNetworkingRequest:query];
132+ - if (body) {
133+ - return callback(nil, body);
134+ + NSDictionary *blob = [RCTConvert NSDictionary:query[@"blob"]];
135+ + NSString *blobId = [RCTConvert NSString:blob[@"blobId"]];
136+ + try {
137+ + //RCTLogError(@"RCTNetworking process handling blob id %@", blobId);
138+ + NSDictionary *body = [handler handleNetworkingRequest:query];
139+ + if (body) {
140+ + return callback(nil, body);
141+ + }
142+ + } catch (NSException *exception) {
143+ + //RCTLogError(@"RCTNetworking process blob id %@ caught %@ because %@", blobId, exception.name, exception.reason);
144+ + NSError *error = [[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorUnknown userInfo:nil];
145+ + //RCTLogError(@"RCTNetworking process blob id %@ returning error to callback.", blobId);
146+ + return callback(error, nil);
147+ }
148+ }
149+ }
0 commit comments