LiveUI / S3

S3 Client written in Swift
MIT License
94 stars 61 forks source link

Files being referenced by URL are not working Linux Issue #10

Open pedantix opened 6 years ago

pedantix commented 6 years ago

Hi! Thanks for the awesome project! So I had this issue where everything worked great on Mac but then when I deployed to a Linux environment I had issues. Uploads were happening but the Data sets were zero. So I investgated and found that this line may be the potential culprit:

https://github.com/LiveUI/S3/blob/master/Sources/S3/Extensions/S3%2BPut.swift#L50 in particular let data: Data = try Data(contentsOf: url)

I checked on swift-corelibs-foundation and found that that was fully implemented so it lead me to wonder if there is something different in the way in which Data is poplulated between the two libraries and what I found was a bit interesting.

I switched my code to do the following:

try req.client().get(url).flatMap(to: File.Response.self) { resp in
            guard let data = resp.http.body.data else {
                throw VGSMError(identifier: "unable to access user image data",
                                reason: "Failure in request mostlikely the readson",
                                source:.capture())
            }
            let file = File.Upload(data: data, destination: destination, access: .publicRead)
            return try req.makeS3Client().put(file: file, on: req)
            }

It was the following.

        return try s3Client.put(file: URL(string: url)!,
                     destination: "image.txt",
                     access: .publicRead,
                     on: req)
                     .map { resp in
                        print("Resp \(resp)")
                        return user
        }

    }

After the switch my code worked just fine.

@rafiki270 you may want to consider using the container Client to request the data here if you wanted I could put a PR together that would change this functionality.

rafiki270 commented 6 years ago

thats a pity ... hmm ... a PR would be obviously fantastic

pedantix commented 6 years ago

👍