cloudinary-go
cloudinary-go copied to clipboard
Base64file uploading to cloudinary is not working
`
func uploadImageToCloudinary(base64str, name string) (*uploader.UploadResult, error) { cloudinaryURL := os.Getenv("CLOUDINARY_URL") cloudinaryClient, err := cloudinary.NewFromURL(cloudinaryURL) if err != nil { return nil, err } formattedString := fmt.Sprintf("data:image/jpeg;base64,%s", base64str)
uploadParams := uploader.UploadParams{
PublicID: name,
UseFilename: true,
UniqueFilename: true,
}
// Upload the Base64 encoded content
result, err := cloudinaryClient.Upload.Upload(context.Background(), formattedString, uploadParams)
if err != nil {
return nil, err
}
return &result, nil
}
`
I tried to do like this and also I tried many but just not working
Hi @bete7512 ,
Thanks for contacting Cloudinary.
I used the below code to upload and it worked fine. Can you please let us know what error are you facing?
func credentials() (*cloudinary.Cloudinary, context.Context) { // Add your Cloudinary credentials, set configuration parameter // Secure=true to return "https" URLs, and create a context //=================== cld, _ := cloudinary.NewFromParams("<CLoudName>", "<API Key>", "<API Secret>") cld.Config.URL.Secure = true ctx := context.Background() return cld, ctx }
func uploadBase64Image(cld *cloudinary.Cloudinary, ctx context.Context) { resp, err := cld.Upload.Upload(ctx, "data:image/png;base64,<YourBase64 Value>", uploader.UploadParams{}) if err != nil { fmt.Println("error") } // Log the delivery URL fmt.Println("2. Upload an image\nDelivery URL:", resp.SecureURL) }
Thanks, Sree
Can u please assign this to me?