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

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

级别: 新人
发帖
1
云币
2
OWr\$lm@z$  
{P?p*2J'  
func ossUpload(_ image: UIImage, bucket: String, callback: @escaping (_ result: Any?, _ error: Any?) -> Void) { btC<>(kl&  
    var originData: Data? M_$;"NS+}  
    var signType: String? KCa @0  
    if let data: Data = UIImagePNGRepresentation(image) { \,nhGh  
        originData = data L Do~  
        signType = "image/png" 4e[ 0.2?  
    } else if let data: Data = UIImageJPEGRepresentation(image, 1.0) { %t.\J:WN;  
        originData = data nH?#_ 5F1  
        signType = "image/jpeg" l,QO+ >)z  
    } else { s<C66z  
        originData = nil SrdCLT8  
        signType = nil L?(1 [jB4G  
    } |M?VmG/6  
     R6o07.]  
    if originData == nil || signType == nil { }&Xf<6  
        return  GXTjK!  
    } 4kNSF  
Y$hLsM\%  
Hg(nC*#/Q  
    let dateFormatter = DateFormatter() _(@ezX.p  
    dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss" n3hlo@gYW  
    dateFormatter.timeZone = NSTimeZone(name: "UTC")! as TimeZone }"^d<dvuz  
    dateFormatter.locale = Locale(identifier: "en-US") C !Lu`y  
    let date = dateFormatter.string(from: Date()) nhq,Y0YH  
     +\B.3%\-  
    let digest = OSSUtil.dataMD5String(originData!) XXW.Uios  
    let sign = "PUT\n\(digest!)\n\(signType!)\n\(date) GMT" m&6I@S2  
`uqsYY`V  
yuZh ak  
    HWNetwork.request(target: .autograph(md5File: digest!, name: "123.jpg", mime: sign, type: "800"), success: { (result) in 7/c9azmC  
        let json = JSON(result) ^;mGOjS  
        print("json===\(json)") //ios-upload-image Et"B8@'P  
        if let path = json["data"]["path"].string{ j2!^iGS}  
            callback(path, nil) EDGAaN*Q  
            return A|0\ct  
        } BIEeHN4  
        if let bucket = json["data"]["bucket"].string{ nc>Ae`"(  
            if let graph = json["data"]["graph"].string{  .Aa(  
                 OD1>s6uA7  
                let endpoint = "https://oss-cn-shenzhen.aliyuncs.com" G2_l}q~  
k/#321Z  
Z= /bD*\g  
                let provider = OSSCustomSignerCredentialProvider.init(implementedSigner: { (result, error) -> String? in mwqe@7  
                    return graph DWar3+u&0  
                }) 2sqNTuO6,|  
Z<Ke /Xi  
-MH~1Tw6Z  
                let client = OSSClient(endpoint: endpoint, credentialProvider: provider!) hX sH9R  
                let put = OSSPutObjectRequest() J@ pCF@'  
                put.bucketName = bucket ]^@!ID$c  
                 x[H9<&)D  
                if let url = json["data"]["url"].string{ &o*f*(C2  
     O'<cEv'B*  
                    put.objectKey = String(url[url.index(url.startIndex, offsetBy: 1)..<url.endIndex]) roG f &  
                    put.uploadingData = originData! ){{]3r  
                    put.objectMeta = ["Date": "\(date) GMT"] G8voqP  
                     +zLh<q0  
                    uploadQueue.async { V9i[ dF  
                         #i~2C@]  
                        let task = client.putObject(put) s+yX82Y  
                        task.continue({ (task:OSSTask) -> Any? in Qh. : N  
                 #}{1>g{sXt  
                            if task.error == nil { F`\7&'I  
                                callback(url, nil) 5PU$D`7it  
                                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 XT 'v7  
                                    // pass \%D/]"@r  
                                    print("success") (VzabO  
                                } ;F!wyTF>}  
                            } else { /_ MEb42&  
                                print("task error-----\(task.error!)") 27!9LU  
                                callback(nil, "error") :. ja~Q  
                            } ?YO$NYwE  
                            return nil SXx2   
                        }).waitUntilFinished() 3bp'UEF^k  
                    } gM<*(=x'  
                } * -Kf  
                 AK*F,H9  
            } ]M;aVw<!  
        } ua]>0\D  
    }) { (error) in qs]7S^yw  
        callback(nil, error) ?u9JRXj%  
    } YQI&8~z  
} okO^ /"  
D<2|&xaR  
62X;gb  
6(`Bl$M9  
]`2=<n;=  
这是我的json打印信息 P'4jz&4  
V@xlm h,  
json==={ ?4U|6|1  
  "code" : 0, 6_# >s1`R  
  "data" : { BQ ol>VRu  
    "graph" : "OSS LTAIBlPDFHyjlxfD:PsbFOVd86djrovoyS3eHpc54bu0=", c bk|LQ.O  
    "url" : "\/icon\/3569686715190237_1531302723861.jpg", D e>'  
    "bucket" : "huiwan-test" od7 [h5r  
  }, x*A_1_A  
  "message" : "success" /OpVr15  
} i$Q$y hT{  
",\,lqV  
g $\Z-!(  
这是报错,不知道签名哪不匹配了。似乎动被截取了一部分? etEm#3  
(YbRYu  
KMxP%dV/=  
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 94umk*ib  
4wZ{Z 2w  
do2~LmeW  
image/jpeg R(c:#KF#8  
Wed, 11 Jul 2018 09:52:03 GMT `JGV3nN  
I$o^F/RH  
/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.} 6]%79?'A  
= dyApR:'  
发表主题 回复主题
« 返回列表上一主题下一主题

限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
验证问题: 阿里云官网域名是什么? 正确答案:www.aliyun.com
上一个 下一个