SDWebImageSwiftUI
SDWebImageSwiftUI copied to clipboard
Download Image From POST Request and display in SwiftUI
First of all, i have placed the issue request but it was closed immediately without me having any solution. Here is the details below
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()
}
}