gpt4 book ai didi

android - Google Cloud Endpoint 发送 Image Base 64

转载 作者:太空狗 更新时间:2023-10-29 15:00:28 25 4
gpt4 key购买 nike

我想从我的 Android 应用程序向我的后端 API 发送图像。所以在我的 android 应用程序中,我将图像转换为 base64 字符串。那部分工作得很好。

安卓代码:

Bitmap resized = Bitmap.createScaledBitmap(AccueilActivity.photo, 720, 1280, true);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
resized.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArray = baos.toByteArray();

String encodedImage = new String(""+Base64.encodeBase64URLSafeString(byteArray));

当我想执行端点 https 请求时,它失败了!

Campagneendpoint endpoint = endpointBuilder.build();
try {
result=endpoint.sendCampagne(encodedImage).execute();
} catch (IOException e) {
e.printStackTrace();
}

我遇到了这个错误:

javax.net.ssl.SSLException: Write error: ssl=0x78edde30: I/O error during system call, Broken pipe

但是如果我直接传递 base64 字符串,它就可以工作!

Campagneendpoint endpoint = endpointBuilder.build();
try {
result=endpoint.sendCampagne("_9j_4AAQSkZJRgABAQAAAQABAAD_2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_wAARCAUAAtADASIAAhEBAxEB_8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL_8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4-Tl5ufo6erx8vP09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raRj_RhHFcb7neixeUI1MjTQ1wcMmpePbuexs1aa1ijjiuY44LgwxpK0sO55LuOBUN4ZGhtbcZupCDczW4iaVkzxmIpQo1MROUoOCtN1YSVOFOCUYSjLmUpN2s_dfvRgr3i2_RwlOdSKjBN6LmaTjFLa8nytRtyQevSTim2pyNnV_iJPZahBbeHYo9QD3BNzLPdyxw3Lq90LcpH5vmhoTMonjX_XxXFypuH3slel_Bv9mnxz8UdctfN0y-tmlaWT7DPb-a0cNtdQygziJ41tp").execute();
} catch (IOException e) {
e.printStackTrace();
}

我试过了,但同样的问题:

String encodedImage = new String(Base64.encodeBase64URLSafeString(byteArray));
String encodedImage = Base64.encodeBase64URLSafeString(byteArray);

只有硬实例化似乎有效:

String encodedImage = "_9j_4AAQSkZJRgABAQAAAQABAAD_2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_wAARCAUAAtADASIAAhEBAxEB_8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL_8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4-Tl5ufo6erx8vP09fb3-Pn6_8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL_8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygp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TjFLa8nytRtyQevSTim2pyNnV_iJPZahBbeHYo9QD3BNzLPdyxw3Lq90LcpH5vmhoTMonjX_XxXFypuH3slel_Bv9mnxz8UdctfN0y-tmlaWT7DPb-a0cNtdQygziJ41tp";

目前我无法将图像发送到我的后端 API,因为有一个我不知道在哪里的错误......任何人已经遇到过这个错误?

最佳答案

问题是我有堆大小溢出,所以在 base64 中转换图像不是一个好主意..

关于android - Google Cloud Endpoint 发送 Image Base 64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27363008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com