Skip to content
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

Ability to specify a folder name in the bucket while saving Parse Fille #417

Closed
aliasad106 opened this issue Sep 17, 2022 · 10 comments
Closed
Labels
type:question Support or code-level question

Comments

@aliasad106
Copy link

aliasad106 commented Sep 17, 2022

New Issue Checklist

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").**

@parse-github-assistant
Copy link

parse-github-assistant bot commented Sep 17, 2022

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.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Sep 17, 2022
@cbaker6
Copy link
Contributor

cbaker6 commented Sep 17, 2022

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: parse-community/parse-server#4899, parse-community/parse-server#6518, parse-community/parse-server-s3-adapter#140 (seems to be the exact issue you are having based on the file name you've been posting in slack), parse-community/parse-server-s3-adapter#16 (comment), parse-community/parse-server-s3-adapter#76, parse-community/parse-server-s3-adapter#171, parse-community/parse-server-s3-adapter#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.

@cbaker6
Copy link
Contributor

cbaker6 commented Sep 17, 2022

The server returns a number of improper errors: parse-community/parse-server#7444, parse-community/parse-server#8029

@cbaker6
Copy link
Contributor

cbaker6 commented Sep 17, 2022

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?

@aliasad106
Copy link
Author

Alright so I check on the latest and now I get this error.
ParseError code=-1 error=Unexpected token � in JSON at position 0

@aliasad106
Copy link
Author

aliasad106 commented Sep 18, 2022

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

@aliasad106
Copy link
Author

aliasad106 commented Sep 18, 2022

So when doing from ParseReact javascript I get the validateFilename method called and I get the name like this "assetsFolder/newAssetNameXYZ".

@cbaker6
Copy link
Contributor

cbaker6 commented Sep 18, 2022

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:
IMG_0444

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 #417 (comment). 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".

@aliasad106
Copy link
Author

aliasad106 commented Sep 18, 2022

@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 /

@cbaker6
Copy link
Contributor

cbaker6 commented Oct 3, 2022

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.

@mtrezza mtrezza closed this as completed Nov 21, 2022
@mtrezza mtrezza added type:question Support or code-level question and removed type:bug Impaired feature or lacking behavior that is likely assumed labels Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

3 participants