-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing request token for request: <NSURLRequest: 0x60000253e5a0> { URL: file:// #29364
Comments
Same issue with |
Same issue with axios after update to 0.63.0 |
The issue is still here with 0.63.1, 100% reproducible on iOS. (tested with fetch and axios) |
Here is a minimal repo that demonstrates this error. Choose a file from the camera roll and then try to retrieve that using fetch. https://github.com/struct78/react-native-0.63.1-missing-request-token |
Hey, I caught up @helderburato and we tried some approaches. This seems an error not much related to TL;DR: We do not manage to correct the issue. But we made some research, discovered something about it, created assumptions but for now, we are downgrading the version of our RN lib to 0.61.4. Here is what we managed to discover! 😄 Some steps to catch what we accomplish:
- (void)start
{
if (_status != RCTNetworkTaskPending) {
RCTLogError(@"RCTNetworkTask was already started or completed");
return;
}
if (_requestToken == nil) {
id token = [_handler sendRequest:_request withDelegate:self];
RCTLog(@"token %@", token); // <- here
RCTLog(@"_handler %@", _handler); // <- here
if ([self validateRequestToken:token]) {
_selfReference = self;
_status = RCTNetworkTaskInProgress;
}
}
}
- (BOOL)validateRequestToken:(id)requestToken
{
BOOL valid = YES;
if (_requestToken == nil) {
if (requestToken == nil) {
if (RCT_DEBUG) {
RCTLog(@"error _handler %@", _handler); // <- here
RCTLog(@"error requestToken %@", requestToken); // <- here
RCTLogError(@"Missing request token for request: %@", _request);
}
valid = NO;
}
_requestToken = requestToken;
} else if (![requestToken isEqual:_requestToken]) {
if (RCT_DEBUG) {
RCTLogError(@"Unrecognized request token: %@ expected: %@", requestToken, _requestToken);
}
valid = NO;
}
/* ... */
} Then I identified an issue with We tried to use a - (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate
{
// create the semaphore
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
__block RCTImageLoaderCancellationBlock requestToken;
requestToken = [self loadImageWithURLRequest:request callback:^(NSError *error, UIImage *image) {
RCTLog(@"error %@", error); // <- log here
if (error) {
[delegate URLRequest:requestToken didCompleteWithError:error];
return;
}
NSString *mimeType = nil;
NSData *imageData = nil;
if (RCTImageHasAlpha(image.CGImage)) {
mimeType = @"image/png";
imageData = UIImagePNGRepresentation(image);
} else {
mimeType = @"image/jpeg";
imageData = UIImageJPEGRepresentation(image, 1.0);
}
RCTLog(@"mimeType %@", mimeType); // <- log here
RCTLog(@"imageData %@", imageData); // <- log here
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
MIMEType:mimeType
expectedContentLength:imageData.length
textEncodingName:nil];
RCTLog(@"response %@", response); // <- log here
[delegate URLRequest:requestToken didReceiveResponse:response];
[delegate URLRequest:requestToken didReceiveData:imageData];
[delegate URLRequest:requestToken didCompleteWithError:nil];
RCTLog(@"delegate %@", delegate); // <- log here
// Release the semaphore
dispatch_semaphore_signal(sema);
}];
// Here we lock until the semaphore release
if (![NSThread isMainThread]) {
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else {
while (dispatch_semaphore_wait(sema, DISPATCH_TIME_NOW)) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0]];
}
}
RCTLog(@"RCTImageLoader requestToken %@", requestToken); // <- log here
return requestToken;
} Hope that helps someone! 😄 |
Hi @caiangums, I actually thought it may be related to the library I was using, so I posted more detail about this issue on their repo. Check it out here: ivpusic/react-native-image-crop-picker#1348 Finally, I remember a strange bug I once had with Android when posting images to the server. It turned out to be related to the Flipper version (#28551). I have tried disabling Flipper totally in RN 63, but this has not solved our issue. However, I thought I would mention it incase those more knowledgable about RN could find a link between the two issues. |
I also have same issue. I use hack for this #29021 (comment). |
Hi @anthony1110! Thanks for mentioning it. I think your solution is a bad approach. Instead of correcting the issue, you avoided an error and considered valid. |
@caiangums , yup, that hack is a bad method, just a temporary hack to make it working. Still require react-native developer to provide a real fix for this issue. |
Good point @anthony1110! I think we all made some progress with our knowledge and maybe when someone from the RN team comes here they will have some ground on where to start. btw does your "hack" generated side-effects? Did you notice something? 🤔 |
find the comment below also i can confirm that my solution worked on ios but not on android. so weird |
Same issue here on 0.63 |
@caiangums , so far so good from my application to upload and download image with the hack. Again, it is still bad hack, still need to wait react-native developer to fix it. Also, I believe upgrade Flipper version will fix the issue but I am not sure how to upgrade Flipper version in IOS/podfile. |
Hey @uusa35, thanks for your reply. My request is for an example to reproduce. As far as I can see, your comment just has some prints from your code and it was traced that the issue may be related to some bug inside the Objective-C RN lib. Just to be clear:
|
The main issue like someone mentioned is within - (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate
{
__block RCTImageLoaderCancellationBlock requestToken;
requestToken = [self loadImageWithURLRequest:request callback:^(NSError *error, UIImage *image) {
if (error) {
[delegate URLRequest:requestToken didCompleteWithError:error];
return;
}
NSString *mimeType = nil;
NSData *imageData = nil;
if (RCTImageHasAlpha(image.CGImage)) {
mimeType = @"image/png";
imageData = UIImagePNGRepresentation(image);
} else {
mimeType = @"image/jpeg";
imageData = UIImageJPEGRepresentation(image, 1.0);
}
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
MIMEType:mimeType
expectedContentLength:imageData.length
textEncodingName:nil];
[delegate URLRequest:requestToken didReceiveResponse:response];
[delegate URLRequest:requestToken didReceiveData:imageData];
[delegate URLRequest:requestToken didCompleteWithError:nil];
}];
return requestToken;
} Error is thrown out because I've managed to fix issue for my project by reverting this commit: 3198009#diff-9a034658197479288c4d346a0eb4d98c |
@ajanauskas Looks promising, but unfortunately it didn't change anything for me. My patch looks like thisdiff --git a/node_modules/react-native/Libraries/Image/RCTLocalAssetImageLoader.mm b/node_modules/react-native/Libraries/Image/RCTLocalAssetImageLoader.mm
index 8669ad3..7a55058 100644
--- a/node_modules/react-native/Libraries/Image/RCTLocalAssetImageLoader.mm
+++ b/node_modules/react-native/Libraries/Image/RCTLocalAssetImageLoader.mm
@@ -49,19 +49,28 @@ - (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
{
- UIImage *image = RCTImageFromLocalAssetURL(imageURL);
- if (image) {
- if (progressHandler) {
- progressHandler(1, 1);
+ __block auto cancelled = std::make_shared<std::atomic<bool>>(false);
+ RCTExecuteOnMainQueue(^{
+ if (cancelled->load()) {
+ return;
}
- completionHandler(nil, image);
- } else {
- NSString *message = [NSString stringWithFormat:@"Could not find image %@", imageURL];
- RCTLogWarn(@"%@", message);
- completionHandler(RCTErrorWithMessage(message), nil);
- }
- return nil;
+ UIImage *image = RCTImageFromLocalAssetURL(imageURL);
+ if (image) {
+ if (progressHandler) {
+ progressHandler(1, 1);
+ }
+ completionHandler(nil, image);
+ } else {
+ NSString *message = [NSString stringWithFormat:@"Could not find image %@", imageURL];
+ RCTLogWarn(@"%@", message);
+ completionHandler(RCTErrorWithMessage(message), nil);
+ }
+ });
+
+ return ^{
+ cancelled->store(true);
+ };
}
@end
Is that all that needs to be done? |
I tested @ajanauskas fix and it is working. Thanks @ajanauskas ! |
This comment has been minimized.
This comment has been minimized.
@keithhackbarth The original issue and error information added to this issue seems pretty iOS specific. If you're seeing something similar on android i'd suggest opening a separate issue. |
Sorry @awinograd . Looks like a more generic discussion is happening on #29021 I'll move my comment over there. |
any update on this ? |
in Replace Below
return nil; With
This.. Like and Love , if it work 👍 |
dataForm.append('file', { uri: Platform.OS=='ios'?photo.uri.replace("file://", "/private"):photo.uri, name: 'photo.jpg', type: 'image/jpg' }); IOS : photo.uri.replace("file://", "/private") It only works for the real device, on simulator still give the error but at least you can deploy your app until this issue is patched |
For now
If you want to lock a version (using latest nightly),
and change the version to "6.3.2" to be be able to install the pods until the make a fix for the nightlies. Or if you want the latest build without any locking
which the Podspecs dont break, but youre at the mercy of new bugs obviously each time you build. |
is that work? |
Yeah there are nightly builds. |
@onebotforyou Don't forget to delete |
@fahelmoreira it works for me on real device thanks!
|
Nice temporary hack! It works in RN 0.63.2 copy the hacked RCTNetworkTask.mm into ios folder. #!/bin/sh chmod +x runThisPodInstall.sh |
Beautiful it works, but can you explain the logic for this? What's private supposed to do? |
React Native 0.63.3 is available now. And in my local testing, this issue is now resolved. Thanks so much, all! |
Great! But is it available in the Expo RN version? |
Glad the fix made it! |
Good job.. thanks a lot |
Can also confirm that with RN 63.3 I am no longer seeing the issue. |
upload form data image with axios fixed with v0.63.3 |
v0.63.3 axio / expo and react native i am still having problem request token in the upload of image formData IOS |
Same issue on v0.63.2 |
@AliUZAR This worked for me. |
@joealba getting this build error after upgrade from 0.63.2 to 0.63.3.
Any idea? |
Error fixed when updating React Native to version 0.63.3 |
it worked. thanks |
#import <React/RCTLocalAssetImageLoader.h> #import #import <React/RCTUtils.h> #import "RCTImagePlugins.h" @interface RCTLocalAssetImageLoader() @implementation RCTLocalAssetImageLoader RCT_EXPORT_MODULE()
return ^{ Class RCTLocalAssetImageLoaderCls(void) {
** rn version : 0.63+ |
I had this same problem in 0.62.2 Only the update to version 0.63.3 solved the problem. Update link: https://react-native-community.github.io/upgrade-helper/?from=0.63.2&to=0.63.3 |
in my mac I needed to do like this (without "/private"):
|
Description
I just upgraded to RN 0.63.0 and all fine, but only for upload using axios, i get
React Native version:
System:
OS: macOS 10.15.5
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 163.19 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.16.1 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 22, 23, 25, 26, 27, 28, 29
Build Tools: 23.0.3, 27.0.3, 28.0.3, 29.0.0, 29.0.2
System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-R | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6514223
Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_221 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.0 => 0.63.0
npmGlobalPackages:
react-native: Not Found
Steps To Reproduce
Here is my code snippet and that gives me error
Expected Results
Should upload file, it was fine in 0.62.2
The text was updated successfully, but these errors were encountered: