阿里云
1024开发者盛宴之Java专家问答专场
发表主题 回复主题
  • 548阅读
  • 0回复

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

级别: 新人
发帖
1
云币
2
;S^"Y:7)  
qy?$t:*pp  
func ossUpload(_ image: UIImage, bucket: String, callback: @escaping (_ result: Any?, _ error: Any?) -> Void) { &p#PYs|H  
    var originData: Data? `~\SQ EY$  
    var signType: String? fahQ^#&d`  
    if let data: Data = UIImagePNGRepresentation(image) { Mm,\e6#*  
        originData = data W0x9^'=s\  
        signType = "image/png" .qe+"$K'n  
    } else if let data: Data = UIImageJPEGRepresentation(image, 1.0) { \x$`/  
        originData = data zdem}kBIe  
        signType = "image/jpeg" sh,4n{+  
    } else { vg?(0Gasm*  
        originData = nil kReZch}  
        signType = nil 5f_x.~ymA  
    } R7b-/ !L  
     V1P]pP  
    if originData == nil || signType == nil { f.` 8vaV  
        return V O1   
    } ~:,}?9  
C:&Sk\   
c{`!$Z'k<  
    let dateFormatter = DateFormatter() m%eCTpYo  
    dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss" dVq9'{[3  
    dateFormatter.timeZone = NSTimeZone(name: "UTC")! as TimeZone >&>EjK4?  
    dateFormatter.locale = Locale(identifier: "en-US") Jo8fMG\P  
    let date = dateFormatter.string(from: Date()) V!*1F1  
     B.?F^m@zS  
    let digest = OSSUtil.dataMD5String(originData!) 1Cc91  
    let sign = "PUT\n\(digest!)\n\(signType!)\n\(date) GMT" f@9XSZ<.71  
F~fN7<9R  
bCTN^  
    HWNetwork.request(target: .autograph(md5File: digest!, name: "123.jpg", mime: sign, type: "800"), success: { (result) in (-1{W^(  
        let json = JSON(result) \ eba9i^  
        print("json===\(json)") //ios-upload-image [Ous|a[)o  
        if let path = json["data"]["path"].string{ Qhe<(<^J,  
            callback(path, nil) -1$z=,q'  
            return 1foG*   
        } IrRe6nf@K  
        if let bucket = json["data"]["bucket"].string{ ~tL:r=  
            if let graph = json["data"]["graph"].string{ JSq3)o9?/  
                 D@5h$ m5  
                let endpoint = "https://oss-cn-shenzhen.aliyuncs.com" c#?~1@=  
ZJFF4($qN  
' 8R5 Tl  
                let provider = OSSCustomSignerCredentialProvider.init(implementedSigner: { (result, error) -> String? in &&jQ4@m}j  
                    return graph 9%R"(X)  
                }) >'m&/&h  
2u0B=0x  
x~m$(LT  
                let client = OSSClient(endpoint: endpoint, credentialProvider: provider!) $zhvI*0  
                let put = OSSPutObjectRequest() e&A3=a~\s  
                put.bucketName = bucket V\n!?1{kdF  
                 iz[IK%K  
                if let url = json["data"]["url"].string{ oFt_ yU-  
     AfZGI'%4[a  
                    put.objectKey = String(url[url.index(url.startIndex, offsetBy: 1)..<url.endIndex]) t\2-7Ohj6  
                    put.uploadingData = originData! 7N5M=f.DS(  
                    put.objectMeta = ["Date": "\(date) GMT"] 7^@ 1cA=S  
                     DqI"B  
                    uploadQueue.async { kE+fdr\ T  
                         .;U?%t_7  
                        let task = client.putObject(put) >pol'=  
                        task.continue({ (task:OSSTask) -> Any? in n Jz*}=  
                 :vS/Lzk  
                            if task.error == nil { <Vh5`-J  
                                callback(url, nil) t"~X6o|R  
                                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 {65Y Tt%  
                                    // pass < uV@/fn<  
                                    print("success") 64y9.PY  
                                } tmeg=U7  
                            } else { u#V;  
                                print("task error-----\(task.error!)") @.dM1DN)  
                                callback(nil, "error") hr&UD|E=  
                            } ignOF  
                            return nil KAT"!b   
                        }).waitUntilFinished() V.+a}J=Cw  
                    } gId :IR  
                } tqt~F2u  
                 rc`Il{~k  
            } w8KxEV=  
        } e-xT.RnQ  
    }) { (error) in t`Xx\  
        callback(nil, error) AGx(IK/_  
    } gxVJH'[V5  
} h-m0Ro?6  
:^x,>( a  
~X;sa,)L1+  
,6A/| K-  
q#8z%/~k  
这是我的json打印信息 f8f|'v|  
%yR 80mn8  
json==={ \pI ,6$'  
  "code" : 0, <rU+{&FKNL  
  "data" : { [H2su|rBI`  
    "graph" : "OSS LTAIBlPDFHyjlxfD:PsbFOVd86djrovoyS3eHpc54bu0=", 09iD| $~  
    "url" : "\/icon\/3569686715190237_1531302723861.jpg", MGo`j:0  
    "bucket" : "huiwan-test" E /ycPqD  
  }, y}W*P#BDO  
  "message" : "success" Wx8 cK=  
} 3 "|A5>Vo  
(d[JMO^@8  
B+'w'e$6  
这是报错,不知道签名哪不匹配了。似乎动被截取了一部分? OJ7y  
UwDoueXs  
%nkbQ2^  
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 L$ju~0jl)%  
<.@w%rvG  
hSk  
image/jpeg z2dW)_fU$  
Wed, 11 Jul 2018 09:52:03 GMT $bk_%R}s  
y8|}bd<Sr  
/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.} r+MqjdXG  
_<)HFg6  
发表主题 回复主题
« 返回列表上一主题下一主题

限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
验证问题: 45 - 44 = ?
上一个 下一个