@@ -184,6 +184,53 @@ public bool Move(string destBucket,string destKey,MAC mac=null){
184
184
}
185
185
}
186
186
187
+ /// <summary>
188
+ /// Uploads the string.
189
+ /// </summary>
190
+ /// <param name="base64Content">Base64 content.</param>
191
+ public void UploadString ( int filesize , string mimeType , string base64Content ) {
192
+ string token = getDefalutToken ( this . bucketName , this . key ) ;
193
+ UploadString ( token , filesize , mimeType , base64Content ) ;
194
+ }
195
+
196
+ /// <summary>
197
+ /// Uploads the string.
198
+ /// </summary>
199
+ /// <param name="token">Token.</param>
200
+ /// <param name="base64Content">Base64 content.</param>
201
+ public void UploadString ( string token , int fileSize , string mimeType , string base64Content ) {
202
+ using ( QiniuWebClient qwc = new QiniuWebClient ( ) ) {
203
+ qwc . UpToken = token ;
204
+ string url = Config . UP_HOST +
205
+ string . Format ( "/putb64/{0}/key/{1}/mimeType/{2}" ,
206
+ fileSize ,
207
+ Base64URLSafe . Encode ( this . key ) ,
208
+ Base64URLSafe . Encode ( mimeType ) ) ;
209
+
210
+ qwc . UploadStringCompleted += ( sender , e ) => {
211
+ if ( e . Error != null && e . Error is WebException ) {
212
+ if ( e . Error is WebException ) {
213
+ QiniuWebException qwe = new QiniuWebException ( e . Error as WebException ) ;
214
+ onUploadFailed ( new QiniuUploadFailedEventArgs ( qwe ) ) ;
215
+ } else {
216
+ onUploadFailed ( new QiniuUploadFailedEventArgs ( e . Error ) ) ;
217
+ }
218
+ } else {
219
+ onQiniuUploadCompleted ( new QiniuUploadCompletedEventArgs ( e . Result ) ) ;
220
+
221
+ onQiniuUploadCompleted ( new QiniuUploadCompletedEventArgs ( e . Result ) ) ;
222
+ }
223
+ } ;
224
+
225
+ qwc . UploadProgressChanged += ( sender , e ) => {
226
+ onQiniuUploadProgressChanged ( new QiniuUploadProgressChangedEventArgs ( e . BytesSent , e . TotalBytesToSend ) ) ;
227
+ } ;
228
+
229
+ qwc . Headers . Add ( "Content-Type" , "application/octet-stream" ) ;
230
+ qwc . UploadStringAsync ( new Uri ( url ) , "POST" , base64Content ) ;
231
+ }
232
+ }
233
+
187
234
/// <summary>
188
235
/// Asyncs the upload.
189
236
/// </summary>
0 commit comments