如何使用AJAX将base64图像发送或流式传输到Node.js Express服务器?

时间:2023-01-12 18:18:57

I am new to working with images in web development. We have a Node.js Express server that will run on Heroku and uses Cloudinary to store images.

我是网络开发中处理图像的新手。我们有一个Node.js Express服务器,它将在Heroku上运行并使用Cloudinary来存储图像。

Ideally we could save images directly to Cloudinary, but I am not sure if that's possible and we are afraid of putting our Cloudinary credentials on the client.

理想情况下,我们可以将图像直接保存到Cloudinary,但我不确定这是否可行,我们害怕将我们的Cloudinary凭据放在客户端上。

Assuming we must send images data to our server first instead of sending them directly to Cloudinary - if the images are encoded as base64 on the client, is it possible to stream the images from the client to the server - or must we send all the data at once? Either way, what headers do we use to send binary / base64 data?

假设我们必须首先将图像数据发送到我们的服务器,而不是直接将它们发送到Cloudinary - 如果图像在客户端上编码为base64,是否可以将图像从客户端流式传输到服务器 - 或者我们必须发送所有数据立刻?无论哪种方式,我们使用什么标头来发送二进制/ base64数据?

is it possible to send or even stream binary data from the client to the server?

是否可以将二进制数据从客户端发送甚至传输到服务器?

since it is a Node.js server, it would be ideal to use streams and to stream the file from our server to Cloudinary.

因为它是一个Node.js服务器,所以使用流并将文件从我们的服务器流式传输到Cloudinary是理想的。

hope this makes sense, and info would be very helpful.

希望这是有道理的,信息将非常有用。

1 个解决方案

#1


2  

Why not using direct uploads from the client side to Cloudinary using the jQuery plugin?

为什么不使用jQuery插件从客户端直接上传到Cloudinary?

This method supports both signed or unsigned uploads, when the signature can (and should) be generated on your server before rendering the page, for privacy reasons. Uploading from Base64 URI is also possible with this mechanism.

出于隐私原因,在呈现页面之前可以(并且应该)在服务器上生成签名时,此方法支持签名或未签名的上载。使用此机制也可以从Base64 URI上载。

Note that Cloudinary's client-libraries also wrap this plugin and provide you with "off the shelf" solutions for embedding the upload-fields in your web app, with the signature already inside.

请注意,Cloudinary的客户端库还包装此插件,并为您提供“现成”解决方案,用于在Web应用程序中嵌入上载字段,签名已在内部。

Let us know if you need any further guidance.

如果您需要任何进一步的指导,请告诉我们。

#1


2  

Why not using direct uploads from the client side to Cloudinary using the jQuery plugin?

为什么不使用jQuery插件从客户端直接上传到Cloudinary?

This method supports both signed or unsigned uploads, when the signature can (and should) be generated on your server before rendering the page, for privacy reasons. Uploading from Base64 URI is also possible with this mechanism.

出于隐私原因,在呈现页面之前可以(并且应该)在服务器上生成签名时,此方法支持签名或未签名的上载。使用此机制也可以从Base64 URI上载。

Note that Cloudinary's client-libraries also wrap this plugin and provide you with "off the shelf" solutions for embedding the upload-fields in your web app, with the signature already inside.

请注意,Cloudinary的客户端库还包装此插件,并为您提供“现成”解决方案,用于在Web应用程序中嵌入上载字段,签名已在内部。

Let us know if you need any further guidance.

如果您需要任何进一步的指导,请告诉我们。