parse-community / Parse-Swift

The Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, Linux, Android, Windows)
https://parseplatform.org
MIT License
308 stars 69 forks source link

Nested ParseFile saves invalid data #425

Open bcbeta opened 2 years ago

bcbeta commented 2 years ago

Issue Description

Deep save of ParseFile creates invalid file.

Steps to reproduce

Adopted from the Files playground. Instead of the ParseFile profilePicture property I created a property that links to a PFPhoto object with nested ParseFiles:

struct GameScore: ParseObject {
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?
    var originalData: Data?

    //: Your own properties.
    var points: Int? = 0
    var photo: PFPhoto?
}
struct PFPhoto: ParseObject {
    //: These are required by ParseObject
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?
    var originalData: Data?

    //: Your own properties.
    var photo: ParseFile?
    var thumbnail: ParseFile?
    var location: ParseGeoPoint?
}

I then save a Score that contains the PFPhoto:

var score = GameScore(points: 52)
        //: Set the link online for the file.
        let linkToFile = URL(string: "https://parseplatform.org/img/logo.svg")!

        //: Create a new `ParseFile` for your picture.

        //: Set the picture as part of your ParseObject
        let photoFile = ParseFile(name: "profile.svg", cloudURL: linkToFile)
         let thumbnailFile = ParseFile(name: "profile.svg", cloudURL: linkToFile)

        var pfPhoto = PFPhoto()
        var photoACL = ParseACL()
        photoACL.publicRead = true
        photoACL.publicWrite = false
        photoACL.setWriteAccess(user: User.current!, value: true)
        pfPhoto.ACL = photoACL
        pfPhoto.photo = photoFile

        pfPhoto.thumbnail = thumbnailFile
        score.photo = pfPhoto

            do {
                try await score.save()
            }
            catch{
                print(error.localizedDescription)
            }

Actual Outcome

When I save a score object, the PFPhoto object is saved but the ParseFiles link to invalid data- https://parsefiles.back4app.com/zgqRRfY6Tr5ICfdPocRLZG8EXK59vfS5dpDM5bqr/thumbnail.jpg

Expected Outcome

The PFPhoto object should contain two valid image files.

Environment

Client

Server

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!