cloudinary-go icon indicating copy to clipboard operation
cloudinary-go copied to clipboard

Base64file uploading to cloudinary is not working

Open bete7512 opened this issue 1 year ago • 2 comments

`

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

bete7512 avatar Aug 11 '23 17:08 bete7512

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

skalahasti-cloudinary avatar Aug 11 '23 21:08 skalahasti-cloudinary

Can u please assign this to me?

AnshShah77 avatar Oct 06 '23 14:10 AnshShah77