在向Google Docs API请求之前,压缩图像(来自公共URI)
我正在尝试从另一个源文档编程构建Google Doc,并且该源文档包含在S3服务器上托管的图片。
因此,基本上,我正在从源文档中获取图像的URI,然后直接与URI进行我的GDOC请求:
const request = [{
insertInlineImage: {
uri: myUriString,
location: {
index: 1
}
},
}];
我的问题是,有时我会从Google Docs服务器中收回此错误:'无效请求:提供的图像太大了。
我在文档必须小于50MB,不能超过25百万像素,并且必须以PNG,JPEG或GIF格式之一。”
因此,基本上,我需要将其复制到Google文档的S3上的一些图像太大而无法直接提出请求。
问题是我不太了解最好的方法(或者甚至可能的话)压缩从S3获得URI和提出GDOC请求之间的图像(因为我只是真正获得URI,而不是Blob
)我需要做一些事情,例如将图像向下拉,压缩图像,然后再次将压缩图像保存到S3,然后将新创建的URL用于GDOCS请求?
这似乎是关于要做的事情,所以我只是想知道是否有人有更好的解决方案。
我的直觉是,我缺少或不了解某些东西。
提前致谢。
I'm trying to build a google doc programmatically from another source doc, and the source document contains pictures that are hosted on an s3 server.
So basically I'm getting the uri for the images from the source doc, then making my gdocs request directly with the uri like this:
const request = [{
insertInlineImage: {
uri: myUriString,
location: {
index: 1
}
},
}];
My problem is that sometimes I'm getting this error back from the google docs server: 'Invalid request: The provided image is too large.'
I found in the documentation that "Images must be less than 50MB in size, cannot exceed 25 megapixels, and must be in one of PNG, JPEG, or GIF format."
So basically some of the images hosted on S3 that I need to copy to google docs are too large to make the request directly.
The problem is I don't really understand the best way (or if it's even possible) to compress the image between getting the uri from s3 and making the gdocs request (since I'm only really getting the uri, not the blob)
Maybe I need to do something like pull the image down, compress it, then save the compressed image again to s3, and then use the newly created url for the gdocs request?
That seems like a very round about thing to do, so I'm just wondering if anyone has a better solution.
My gut feeling is that there is something I'm missing or not understanding.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了减少图像大小和图像数据大小,以下流程如何?该流程用于使用Google API降低图像大小和图像数据大小。
流:
https://lh6.googleusercontent.com/### #k = s220
。https://lh6.googleusercontent.com/####k = s1000
。= S220
被修改为= S1000
。参考:
In order to reduce the image size and image data size, how about the following flow? This flow is used for reducing the image size and image data size using Google API.
Flow:
https://lh6.googleusercontent.com/###k=s220
.https://lh6.googleusercontent.com/###k=s1000
.=s220
is modified to=s1000
.Reference: