SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.14k stars 219 forks source link

Download image from Post request #210

Closed nick70007 closed 2 years ago

nick70007 commented 2 years ago

Hello sir, in my SwiftUI app i am storing images to IPFS Data Store and they have recently made the url as a POST request from GET request. In that case the third party library is not able to render the image. How can i resolve this?

This is the example url i am trying to render

https://ipfs.infura.io:5001/api/v0/cat?arg=QmVHLDEY4DhzJeW7G47QgpdibU6QX8g8He6CS83qRbpcDB

This is the exact error i get:

Error Domain=SDWebImageErrorDomain Code=2001 "Download marked as failed because of invalid response status code 405" UserInfo={SDWebImageErrorDownloadResponseKey=<NSHTTPURLResponse: 0x600000ed8340> { URL: https://ipfs.infura.io:5001/api/v0/cat?arg=QmVHLDEY4DhzJeW7G47QgpdibU6QX8g8He6CS83qRbpcDB } { Status Code: 405, Headers { "Content-Length" = ( 28 ); "Content-Type" = ( "text/plain; charset=utf-8" ); Date = ( "Thu, 03 Mar 2022 17:20:01 GMT" ); Vary = ( Origin ); "X-Content-Type-Options" = ( nosniff ); "X-Robots-Tag" = ( noindex ); } }, NSLocalizedDescription=Download marked as failed because of invalid response status code 405, SDWebImageErrorDownloadStatusCodeKey=405}

My code snippet:

ForEach(vm.item.tabImagesArray.indices, id: .self) { index in

                WebImage(url: URL(string: vm.item.tabImagesArray[index]))
                    .resizable()
                    .placeholder {
                        Image("placeholder")
                            .resizable()
                            .frame(width: 30, height: 30, alignment: .center)
                            .scaledToFit()
                    }
                    .onFailure { error in
                        print(error)
                    }
                    .onSuccess { img, data, _ in
                        print(img)
                        print(data)
                    }
                    .transition(.fade(duration: 0.5))
                    .frame(height: vm.index == index ? 200 : 150)
                    .cornerRadius(15)
                    .padding(.horizontal)
                    .tag(index)
                    .onTapGesture {
                            self.selectedImage = vm.item.tabImagesArray[index]
                            self.showImage.toggle()
                    }
            }
dreampiggy commented 2 years ago

Use https://sdwebimage.github.io/SDWebImage/Classes/SDWebImageDownloaderConfig.html#/c:objc(cs)SDWebImageDownloaderConfig(py)acceptableStatusCodes to change the accept status code.

Or you can use the Response Modifier to filter and map this 405 response to 200.

nick70007 commented 2 years ago

how do i do it with request modifer and where i have to call it in my swift ui app @dreampiggy sir