阿里云
发表主题 回复主题
  • 360阅读
  • 0回复

[求助]iOS阿里云上传图片不成功

级别: 新人
发帖
1
云币
2
Uene=Q6>  
uH{'gd,q8  
func ossUpload(_ image: UIImage, bucket: String, callback: @escaping (_ result: Any?, _ error: Any?) -> Void) { *g7DPN$aQ  
    var originData: Data? /6tcSg)  
    var signType: String? @EZ>f5IO+  
    if let data: Data = UIImagePNGRepresentation(image) { oXal  
        originData = data ,b.n{91[]x  
        signType = "image/png" tY_5Pz(@  
    } else if let data: Data = UIImageJPEGRepresentation(image, 1.0) { 3 N%{B  
        originData = data qo;)X0 N  
        signType = "image/jpeg" Ye |G44z  
    } else { aqL<v94wX  
        originData = nil Q"}s>]k3_  
        signType = nil j$P I,`  
    } TVkcDS  
     Yn<)k_kp  
    if originData == nil || signType == nil { #+G`!<7/@f  
        return tgN92Q.i6T  
    } >>V&yJ_  
P;GprJ`l  
\y~)jq:d"  
    let dateFormatter = DateFormatter() {nRUH*(d9  
    dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss" uPU#c\  
    dateFormatter.timeZone = NSTimeZone(name: "UTC")! as TimeZone wRbw  
    dateFormatter.locale = Locale(identifier: "en-US") l2/ @<0P  
    let date = dateFormatter.string(from: Date()) R}k69-1vL  
     I~RcOiL)  
    let digest = OSSUtil.dataMD5String(originData!) !; WbOnLP  
    let sign = "PUT\n\(digest!)\n\(signType!)\n\(date) GMT" ~e^)q>Lb7(  
,"H?hFQ  
4A  o{M  
    HWNetwork.request(target: .autograph(md5File: digest!, name: "123.jpg", mime: sign, type: "800"), success: { (result) in 7A0dl}:  
        let json = JSON(result) p#<nK+6.8  
        print("json===\(json)") //ios-upload-image %UG/ak%z  
        if let path = json["data"]["path"].string{ %EIUAG  
            callback(path, nil) ~XQ$aRl&  
            return Zd XKI{b  
        } Oga1u  
        if let bucket = json["data"]["bucket"].string{ npj5U/  
            if let graph = json["data"]["graph"].string{ _LsYMUe  
                 I}%mfojC  
                let endpoint = "https://oss-cn-shenzhen.aliyuncs.com" $Sw,hb  
E7 L bSZ  
s((b"{fFb  
                let provider = OSSCustomSignerCredentialProvider.init(implementedSigner: { (result, error) -> String? in k(9s+0qe  
                    return graph `skH-lk,  
                }) d~/xGB`<  
](n69XX_  
*vD/(&pQ1:  
                let client = OSSClient(endpoint: endpoint, credentialProvider: provider!) QpJ IDM/  
                let put = OSSPutObjectRequest() #:I^&~:  
                put.bucketName = bucket wOM<X hZ  
                 i8eA_Q  
                if let url = json["data"]["url"].string{ iz(m3k:w  
     QU%N*bFW%P  
                    put.objectKey = String(url[url.index(url.startIndex, offsetBy: 1)..<url.endIndex]) 9Q=>MOB-  
                    put.uploadingData = originData! #4lHaFq  
                    put.objectMeta = ["Date": "\(date) GMT"] s)Gb!-``  
                     `U!(cDY  
                    uploadQueue.async { d4V 2[TX  
                         wvX"D0eVn  
                        let task = client.putObject(put) H! #5!m&  
                        task.continue({ (task:OSSTask) -> Any? in V"BVvSNu  
                 Bd QQ9$@5  
                            if task.error == nil { Qw}xGlF,  
                                callback(url, nil) (w}r7`n  
                                App.apollo.perform(mutation: CreateAttachmentMutation(path: url, md5: digest!, size: Long(originData!.count), width: Long(image.size.width), height: Long(image.size.height), isImage: true)) { (_, _) in nHE+p\  
                                    // pass _3I3AG0e  
                                    print("success") zK,~37)\  
                                } @_(nd57oSs  
                            } else { .^BWR  
                                print("task error-----\(task.error!)") Qk|( EFQ9  
                                callback(nil, "error") tI `w;e%HN  
                            } ;g6 nHek  
                            return nil F6~b#Jz&i  
                        }).waitUntilFinished() (tTLK0V-|3  
                    } E8+8{ #f;  
                } W;5N04ko  
                 C CC4(v  
            } Qz'O{f  
        } ER/\ +Z#Z  
    }) { (error) in FyQOa)5  
        callback(nil, error) )0'Y et}  
    } p0"BO4({{  
} ><MGZ?-N  
H 3W_}f  
5/*)+  
k&n\ =tKN  
Ty)gPh6O  
这是我的json打印信息 bBd*}"v^"  
hg(KNvl  
json==={ w;@`Yi.WQ  
  "code" : 0, =B1`R%t  
  "data" : { 3xc:Y> *`  
    "graph" : "OSS LTAIBlPDFHyjlxfD:PsbFOVd86djrovoyS3eHpc54bu0=", Z?vY3)  
    "url" : "\/icon\/3569686715190237_1531302723861.jpg", FuIWiO(  
    "bucket" : "huiwan-test" Fj '\v#h  
  }, T9aTEsA[U  
  "message" : "success" ,"4X&>_f  
} =iA"; x  
3 ATN?V@  
jJiCF,m  
这是报错,不知道签名哪不匹配了。似乎动被截取了一部分? P1M|f4*  
lsTe*Od  
Fo--PtY`p  
task error-----Error Domain=com.aliyun.oss.serverError Code=-403 "(null)" UserInfo={__name=Error, HostId=huiwan-test.oss-cn-shenzhen.aliyuncs.com, Code=SignatureDoesNotMatch, OSSAccessKeyId=LTAIBlPDFHyjlxfD, RequestId=5B45D3448EE2472B572FAEDA, StringToSign=PUT k i~Raa/e  
r>n8`W  
g;| n8]  
image/jpeg _Eet2;9  
Wed, 11 Jul 2018 09:52:03 GMT BN bb&]  
#l8K8GLuf  
/huiwan-test/icon/3569686715190237_1531302723861.jpg, StringToSignBytes=50 55 54 0A 0A 69 6D 61 67 65 2F 6A 70 65 67 0A 57 65 64 2C 20 31 31 20 4A 75 6C 20 32 30 31 38 20 30 39 3A 35 32 3A 30 33 20 47 4D 54 0A 2F 68 75 69 77 61 6E 2D 74 65 73 74 2F 69 63 6F 6E 2F 33 35 36 39 36 38 36 37 31 35 31 39 30 32 33 37 5F 31 35 33 31 33 30 32 37 32 33 38 36 31 2E 6A 70 67, SignatureProvided=PsbFOVd86djrovoyS3eHpc54bu0=, Message=The request signature we calculated does not match the signature you provided. Check your key and signing method.} LWp?U!N  
oZ|{J  
发表主题 回复主题
« 返回列表上一主题下一主题

限100 字节
批量上传需要先选择文件,再选择上传
 
验证问题: ECS是阿里云提供的什么服务? 正确答案:云服务器
上一个 下一个