-
-
Notifications
You must be signed in to change notification settings - Fork 69
Wrong image data when fetching image #226
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
Comments
@novemTeam can you fill out the complete issue template? It looks like you removed information |
@cbaker6 I updated it. I still left out the Database info because I am just using Back4App |
What happens when you use the latest version of Xcode 12? If this only occurs in Xcode 13 beta, it's probably not worth a fix until 13 goes Gold. If you can find some documentation that states Xcode 13 is changing the way downloaded data is handled, then I can take a look to see how to adjust. |
It did always work in Xcode 12. |
PR #212 uses Xcode 13 beta 5. I believe there are test cases that cover this scenario that don't fail on Xcode 13. Can you look through them to verify? Parse-Swift/Tests/ParseSwiftTests/ParseFileTests.swift Lines 966 to 969 in 5994d63
If I understand the issue you are saying is present,
Note that you can comment out these lines: Parse-Swift/Tests/ParseSwiftTests/ParseFileTests.swift Lines 944 to 955 in 5994d63
and set these to your Parse Server, Parse-Swift/Tests/ParseSwiftTests/ParseFileTests.swift Lines 31 to 35 in 5994d63
|
@cbaker6 Sorry for the late response, kinda busy. I'll take a closer look this weekend. |
@cbaker6 I was unable to run the Tests because of lack of experience. But I do indeed think there should be a test to check if the file at Maybe something like this? I don't know if there is a better way to check if it is a image.
I also tried a few more things. I ran my project with Xcode 13 on my friends iPhone, and had the same issue. The images don't download correctly. It also changes, 1/10 times it downloads correctly, the other times i get images with a path in it. See the screenshots Here are some more screenshots |
I checked this in Playgrounds (macOS) using Xcode 13 beta 5 (if you look in the folder directory, all of the ParseFiles are intact): Parse-Swift/ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift Lines 42 to 97 in 1a30fb6
as well as in a sample app (iOS) of mine that heavily uses ParseFile for pictures: https://github.com/netreconlab/SnapCat I didn't see the issue you mentioned and everything seems to be working correctly. I recommend looking into other areas of how you are handling files in your app or maybe your server configuration. Tested with Parse Server 4.5.0 and 4.10.3 |
You should also checkout your cache policy: Parse-Swift/Sources/ParseSwift/Parse.swift Lines 70 to 74 in 1a30fb6
You can enable CORS in your const cors = require('cors');
var app = express();
app.use(cors());
... |
@cbaker6 is this something I can change when using Back4App? Also, did you run your test on iOS 15? Because I really can't see what I could be doing wrong when downloading images... I just followed the documentation |
I’m not sure how Back4app works as I self-host, but if you have access to your index.js file you can add it.
My tests in #226 (comment) Used iOS 15 specifically and I didn’t have any issues. |
I get these logs:
Really breaking my head around this. Can't find what's going on |
Update: So I am able to download images the first time, but then there is something wrong with the data at |
@cbaker6 Your code returns a UIImage, but I need the data.
then changed it to this :
This also printed me that path, and not an image. (It printed 137 bytes, so I know this is that path line. It's way to small to be my image) This makes me think that it has something to do with the fetch to the localURL, and not my code.. But it's weird you don't have this issue. |
Update: |
What happens when you don’t add “App Groups”? |
I will not ba able to test out your zip files. Instead, you should attempt to make your case repeatable as a failing test case and submit the PR. you also mentioned your server is 4.4.0, does the problem still persist on the latest server 4.10.3? |
I tested the zip project on my computer and I had the same issue. Xcode 13-beta-5 |
As I’ve stated previously #226 (comment), the zip files don’t mean much. It seems the issue may be something with “app groups” or even how you are using app groups and files. I don’t see this issue at all with the apps I pointed to using Xcode beta 5 or the RC. As I’ve also stated #226 (comment), you testing on a beta when the real version isn’t even out yet. Whatever the issue is, you need to create a failing testcase and a PR (as the issue template states) in order for it be addressed. If either of you submit a PR in the correct format, it will be reviewed. |
Also, both of you are mentioning that you are not only testing on a beta Xcode, you are even testing on a beta Mac OS, Monterey. There’s not even CI for this in GitHub Actins. If you find a reasonable solution, add the correct test cases that don’t break the current CI, then I’ll review the PR. |
@cbaker6 iOS 15 launched yesterday, and Xcode is also out of Beta. I found that it has nothing to do with App Groups. I will take a look at it next week. If I find a fix, I'll create a PR. I also have this issue on both macOS as iOS. |
You tested on macOS Big Sur or Monterey? Monterey is still in beta |
In addition, have you tried your apps on “real” iOS 15 devices. Using the released version of iOS 15, I don’t have any issues with posting and fetching photos in the apps I mentioned above. I recommend checking and clarifying if you are 1) Running Monterey beta 2) running it on an Intel or M1 machine 3) Are your issues present on Big Sur 4) Do you have issues running on real iOS 15 devices? I personally don’t develop on a beta macOS and I cannot replicate any of the issues mentioned on anything that is actually released, nor can the CI replicate it. If you choose to develop on beta software you are choosing to encounter the risk of buggy behavior and may need to modify code on your own to support. |
@cbaker6 Yes its on Monterey. Its running on an Intel iMac. But I actually started noticing the issue on the Beta software of iOS 15. I'll know more next week to see if it still persists on the official version of iOS 15. Also want to mention that this issue is not a really big problem for my app. I started recreating my app in Swift instead of objective c. So i then knew that ParseSwift was in a really early stage so things could fail. I also decided to target iOS 15 and macOS Monterey since Swift and SwiftUI got some important/big improvements. So the version I am developing now is not in production yet. So next week I'll know more and investigate the issue more and keep you informed. |
@cbaker6 Also want to point out, that I am now on the official version of iOS 15. But I still have this issue. First time fetching images is no issue. But fetching that exact same image a second time messes up the cache file I think. To find these files I needed to dig in hidden folders, and found out that these are the folders where Apple caches things. |
In the File I made a video to highlight the problem, maybe this helps you understand a little bit better. |
I updated one of my systems to Monterey and all of the ParseFileTests.swift passes. I also tried the SnapCat app I linked earlier and it worked fine. You can test the |
Hmm, I literately have no idea where I could be doing something wrong |
If you are uploading manually through the dashboard maybe the dashboard doesn't send the same info the Swift SDK sends when saving the photo. If so, it can possibly be a dashboard bug or, you are not uploading properly. |
Yes, maybe, but do you have an idea why the first download does work, but on second attempt not? |
I actually might... This may be a small bug related to caching. When you call your second fetch, do: let fetchedFile2 = try parseFile.fetch(options: [.cachePolicy(.reloadIgnoringLocalCacheData)]) and tell me if it works. I'll post a potential patch soon for you to test. |
The label |
I'll try out #272 for some of my users in a few days. But it seems like this fixed this issue |
If a developer comes across this thread and is using Swift SDK < 2.2.0, the workaround was mentioned in #226 (comment) and #226 (comment). Essentially change the cache policy during your file fetch: let fetchedFile2 = try parseFile.fetch(options: [.cachePolicy(.reloadIgnoringLocalCacheData)]) |
@cbaker6 Is it correct that I need to add the I notice that unchanged file on the server return my corrupted data if I Changing it to |
You would add |
Then it's still a bug. I had a new file that got uploaded via ParseSwift, and on another device, the first download is fine. But on second attemp it's the corrupted filedata again. Adding the custom cachePolicy fixes the issue for me. But I don't know if you think there might be a bug somewhere else? |
I think nobody has this issue because they are not fetching a static file multiple times. But in my case, I need it to be able to fetch a file multiple times. It looks like if the file is already downloaded, it takes the path to that cached file and puts in the file Parse creates. But this only happens if the filename is the exact same, and if it already cached that file via I don't know i you think this is a issue, or worth spending time at. But for me it's fixed by adding the cachePolicy. Maybe for developers with the same issue? |
I've tested it and don't see any issues. If you find a bug, you can open an issue. I recommend you look at my earlier comment #226 (comment) and if you can't find a bug or fix your problem, then add the cache policy |
This should work, fetching a file with the same url should yield the same file, so it's better to use cache. If you are changing the file, it should have a different url than the previous file or you should ignore cache. |
Looking at your old screenshots in #226 (comment), the first file has some data, though I don’t know what it is, I will assume it’s correct. The second time you attemp to fetch the same file it should hit the cache and shouldn’t produce a .tmp file (unless you changed the url or filename). It should point to the parse directory containing the first file where it contains the correct file name and extension from the first download. The data contained in that file should be the exact same data from the first .tmp file. |
That's not the case with me. It clearly show that it does something which results in the file data being a path instead of the actual data. After work, I'll try to look where I can change the file from your #226 comment on back4app. Maybe that's the issue, I'll see... |
I wouldn’t say it’s clear, at least not to me:
To me, you have a lot of moving parts that need to be debugged. If you use your app with another SDK that uses cache, that might provide some insight. |
Be sure to clear you cache, |
New Issue Checklist
Issue Description
I am seeing issues when fetching an image. When i fetch an image for the first time, it loads the image corretly. But when it then tries to load for the second time, the image is broken. I looked at what the downloaded image looks like when opening in a text editor.
I noticed it doesn't contain data, but a path. This is an example:
file:\/\/\/var\/folders\/y5\/3qbps9t11cb2fz7lh1x8bw7w0000gn\/T\/com.app.myApp\/CFNetworkDownload_rDopeR.tmp
My uploaded images in the Database are valid images.
I want to point out that this way of fetching images always worked for me. It's since the Beta's that there is something wrong, but I don't find anything on the Apple Developer known issues page.
Steps to reproduce
This is an example of code I use.
This is my log:
Actual Outcome
file:\/\/\/var\/folders\/y5\/3qbps9t11cb2fz7lh1x8bw7w0000gn\/T\/com.app.myApp\/CFNetworkDownload_rDopeR.tmp
Expected Outcome
Image data
Failing Test Case / Pull Request
Environment
Parse Swift
1.9.8
iOS, macOS
iOS 15 Beta 8, Monterey 12.0 Beta 6
Server
4.4.0
Back4App
Logs
The text was updated successfully, but these errors were encountered: