@@ -458,6 +458,51 @@ public async Task<String> UploadAsync(string command, CancellationToken cancel,
458458 return json ;
459459 }
460460 }
461+ /// <summary>
462+ /// Perform an <see href="https://ipfs.io/docs/api/">IPFS API command</see> that
463+ /// requires uploading of a "file".
464+ /// </summary>
465+ /// <param name="command">
466+ /// The <see href="https://ipfs.io/docs/api/">IPFS API command</see>, such as
467+ /// <see href="https://ipfs.io/docs/api/#apiv0add">"add"</see>.
468+ /// </param>
469+ /// <param name="cancel">
470+ /// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
471+ /// </param>
472+ /// <param name="data">
473+ /// A <see cref="Stream"/> containing the data to upload.
474+ /// </param>
475+ /// <param name="name">
476+ /// The name associated with the <paramref name="data"/>, can be <b>null</b>.
477+ /// Typically a filename, such as "hello.txt".
478+ /// </param>
479+ /// <param name="options">
480+ /// The optional flags to the command.
481+ /// </param>
482+ /// <returns>
483+ /// A task that represents the asynchronous operation. The task's value is
484+ /// the HTTP response as a <see cref="Stream"/>.
485+ /// </returns>
486+ /// <exception cref="HttpRequestException">
487+ /// When the IPFS server indicates an error.
488+ /// </exception>
489+ public async Task < Stream > Upload2Async ( string command , CancellationToken cancel , Stream data , string name , params string [ ] options )
490+ {
491+ var content = new MultipartFormDataContent ( ) ;
492+ var streamContent = new StreamContent ( data ) ;
493+ streamContent . Headers . ContentType = new MediaTypeHeaderValue ( "application/octet-stream" ) ;
494+ if ( string . IsNullOrEmpty ( name ) )
495+ content . Add ( streamContent , "file" , unknownFilename ) ;
496+ else
497+ content . Add ( streamContent , "file" , name ) ;
498+
499+ var url = BuildCommand ( command , null , options ) ;
500+ if ( log . IsDebugEnabled )
501+ log . Debug ( "POST " + url . ToString ( ) ) ;
502+ var response = await Api ( ) . PostAsync ( url , content , cancel ) ;
503+ await ThrowOnErrorAsync ( response ) ;
504+ return await response . Content . ReadAsStreamAsync ( ) ;
505+ }
461506
462507 /// <summary>
463508 /// TODO
0 commit comments