@@ -285,7 +285,7 @@ func (c *VercelBlobClient) List(options ListCommandOptions) (*ListBlobResult, er
285285// be used to later download the blob.
286286func (c * VercelBlobClient ) Put (pathname string , body io.Reader , options PutCommandOptions ) (* PutBlobPutResult , error ) {
287287
288- if pathname == "" {
288+ if len ( pathname ) == 0 {
289289 return nil , NewInvalidInputError ("pathname" )
290290 }
291291
@@ -418,6 +418,59 @@ func (c *VercelBlobClient) Delete(urlPath string) error {
418418 return nil
419419}
420420
421+ func (c * VercelBlobClient ) Copy (fromUrl , toPath string , options PutCommandOptions ) (* PutBlobPutResult , error ) {
422+ if len (fromUrl ) == 0 {
423+ return nil , NewInvalidInputError ("fromUrl" )
424+ }
425+
426+ if len (toPath ) == 0 {
427+ return nil , NewInvalidInputError ("toPath" )
428+ }
429+
430+ apiUrl := c .getAPIURL (toPath )
431+
432+ req , err := http .NewRequest (http .MethodPut , apiUrl , nil )
433+ if err != nil {
434+ return nil , err
435+ }
436+
437+ req .URL .Query ().Add ("fromUrl" , fromUrl )
438+
439+ c .addAPIVersionHeader (req )
440+ err = c .addAuthorizationHeader (req , "put" , toPath )
441+ if err != nil {
442+ return nil , err
443+ }
444+
445+ if ! options .AddRandomSuffix {
446+ req .Header .Set ("X-Add-Random-Suffix" , "0" )
447+ }
448+ if options .ContentType != "" {
449+ req .Header .Set ("X-Content-Type" , options .ContentType )
450+ }
451+ if options .CacheControlMaxAge > 0 {
452+ req .Header .Set ("X-Cache-Control-Max-Age" , strconv .FormatUint (options .CacheControlMaxAge , 10 ))
453+ }
454+
455+ client := & http.Client {}
456+ resp , err := client .Do (req )
457+ if err != nil {
458+ return nil , err
459+ }
460+ defer resp .Body .Close ()
461+
462+ if resp .StatusCode != http .StatusOK {
463+ return nil , c .handleError (resp )
464+ }
465+
466+ var result PutBlobPutResult
467+ if err = json .NewDecoder (resp .Body ).Decode (& result ); err != nil {
468+ return nil , err
469+ }
470+
471+ return & result , nil
472+ }
473+
421474// Download a blob from the blob store
422475//
423476// # Arguments
0 commit comments