mvp implementation
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package officeconvertclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// UploadPPTX uploads a local PPTX using the presigned URL from CreateConversion.
|
||||
func (c *Client) UploadPPTX(
|
||||
ctx context.Context,
|
||||
uploadURL string,
|
||||
localPPTXPath string,
|
||||
) error {
|
||||
file, err := os.Open(localPPTXPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open pptx: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
return c.uploadReader(ctx, uploadURL, file)
|
||||
}
|
||||
|
||||
func (c *Client) uploadReader(ctx context.Context, uploadURL string, body io.Reader) error {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPut, uploadURL, body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build upload request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/vnd.openxmlformats-officedocument.presentationml.presentation")
|
||||
|
||||
res, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("upload pptx: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||
return fmt.Errorf("upload failed with status %d", res.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user