Parse-Swift
Parse-Swift copied to clipboard
Ability to specify a folder name in the bucket while saving Parse Fille
New Issue Checklist
- [ x] I am not disclosing a vulnerability.
- [ x] I am not just asking a question.
- [x ] I have searched through existing issues.
- [ x] I can reproduce the issue with the latest versions of Parse Server and the Parse Swift SDK.
Issue Description
I'm not able to save files within a bucket from Parse Swift. As it's not able specify directory name.
Steps to reproduce
just save a ParseFille
if let jpegData = croppedImage.resized(toWidth: UIScreen.main.bounds.width) {
let fileName = ("userAvatars/newFile" + ".jpg")
let avatar = ParseFile(name:fileName,
data: jpegData,
options: [.mimeType("image/jpg")])
avatar.save(completion: { result in
switch result{
case .success(let file):
print(file.name)
case .failure(let error):
print(error)
}
})
}
Actual Outcome
**ParseError code=-1 error=Invalid struct: No value associated with key CodingKeys(stringValue: "name", intValue: nil) ("name").**
Expected Outcome
It should upload the file in userAvatars directory in the bucket.
Environment
Parse Swift 4.7.0 Parse Server 5.2.1
Client
- Parse Swift SDK version:
4.7.0 - Xcode version:
13.4.1 - Operating system (iOS, macOS, watchOS, etc.):
iOS 15 - Operating system version:
12.4
Server
- Parse Server version:
5.2.1 - Operating system:
linux - Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
Digital Ocean
Database
- System (MongoDB or Postgres):
MongoDB - Database version:
6 - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
MongoDB Atlas
Logs
**ParseError code=-1 error=Invalid struct: No value associated with key CodingKeys(stringValue: "name", intValue: nil) ("name").**
Thanks for opening this issue!
- ❌ Please edit your post and use the provided template when creating a new issue. This helps everyone to understand your post better and asks for essential information to quicker review the issue.
ParseError code=-1 error=Invalid struct: No value associated with key CodingKeys(stringValue: "name", intValue: nil) ("name").
If you are receiving this error when attempting to save a ParseFile it is because the "Parse Server" is not returning the saved ParseFile correctly. In fact, it's not even throwing a proper ParseError and is instead returning something that looks like: ["error": "request entity too large"] which is missing the JSON key code. You will need to update to ParseSwift 4.14.1 to see the error you are getting from the server as that can handle the incorrect format of a ParseError the "Parse Server" is throwing.
In addition, there are a number of issues on the S3 adapter that eludes to this being a server issue: https://github.com/parse-community/parse-server/issues/4899, https://github.com/parse-community/parse-server/issues/6518, https://github.com/parse-community/parse-server-s3-adapter/issues/140 (seems to be the exact issue you are having based on the file name you've been posting in slack), https://github.com/parse-community/parse-server-s3-adapter/issues/16#issuecomment-408078500, https://github.com/parse-community/parse-server-s3-adapter/pull/76, https://github.com/parse-community/parse-server-s3-adapter/issues/171, https://github.com/parse-community/parse-server-s3-adapter/issues/175 (the issue you opened, if it can save "properly", it should be able to delete), along with the many details I sent on slack when this issue was posted. Lastly, you should be looking for Parse Server documentation/code that demonstrates this feature is "officially" available on the Parse-Server/Parse-S3-Adapter. If it isn't officially supported, you should open your issue in one of those repos are or for this issue to be moved to the necessary repo.
The server returns a number of improper errors: https://github.com/parse-community/parse-server/issues/7444, https://github.com/parse-community/parse-server/issues/8029
- [x] I can reproduce the issue with the latest versions of Parse Server and the Parse Swift SDK.
Also, please uncheck the box above as the latest version of the Swift SDK at the time of your post was 4.14.0 and you stated when your issue occurred:
Client
Parse Swift SDK version: 4.7.0 Xcode version: 13.4.1 Operating system (iOS, macOS, watchOS, etc.): iOS 15 Operating system version: 12.4
You should also report the specific version and location of the Parse Server S3 Adapter you are using along with the options you have set. For example, you posted an issue about file names and the documentation for the S3 adapter clearly has an option for validateFilename that you never posted. What file name outputs in this function to the console log when using JS/Swift? Is your validation function non-existent or broken?
Alright so I check on the latest and now I get this error.
ParseError code=-1 error=Unexpected token � in JSON at position 0
Since I'm doing same thing from javascript sdk as well, It works there.
When doing same from ParseSwift the validateFilename never gets called. and we get similar errors on both server and parse swift
SyntaxError: Unexpected token � in JSON at position 0 at JSON.parse (<anonymous>) at createStrictSyntaxError
So when doing from ParseReact javascript I get the validateFilename method called and I get the name like this "assetsFolder/newAssetNameXYZ".
SyntaxError: Unexpected token � in JSON at position 0 at JSON.parse (
) at createStrictSyntaxError
This is literally the same exact error message I posted in the Parse Slack:

You are proving the point I’ve stated many times, “it is a server error”. It doesn’t matter that it works with the JS SDK (I proved this in the slack discussion). You need to read the links in https://github.com/parse-community/Parse-Swift/issues/417#issuecomment-1250111678. They tell you exactly where to look for the “server issue”. I literally linked PR’s and issues that say the exact same thing. The links also state, word-for-word it's reasonable to allow the / separator in the file name if you wish to store the file in a subpath. This will require changes on parse-server..
Your issue will not be fixed until you transfer your issue to the parse-server or the parse s3 adapter. It’s "not a Swift SDK issue" it's a "server issue".
@cbaker6 The issue was resolved on the server side. I think it's some kind of decoding issue on ParseSwift's end
because I am sending name from javascript sdk like this
folderName + "%2F" + name + "." + fileExtension; and the same server creates the folder and saves file.
when I do the same from ParseSwift it fails to create folder. I guess ParseSwift is not able to encode/decode name with %2F which is /
Related discussion which states they receive the same type of error using JS. As I've mentioned many times now, this looks to be a server issue and not related to the Swift SDK.