我试图将.png文件上传到Azure IoT Hubs,但由于某些原因,我不断收到BAD_FORMAT。我使用的是 com.microsoft.azure.sdk.iot:iot-device-client:1.14.2。 库,因为我需要使用一个相当老的安卓设备(KitKat版本)。
我正在使用的代码。
public void btnFileUploadOnClick(View v) throws URISyntaxException, IOException
{
Log.i("IoT App","Uploading file to IoT Hub...");
EditText text = (EditText)findViewById(R.id.editTextFileName);
String fullFileName = text.getText().toString();
try
{
File directory = Environment.getExternalStorageDirectory();
File file = new File(directory, "payments.json");
InputStream inputStream = new FileInputStream(file);
long streamLength = file.length();
if(file.isDirectory())
{
throw new IllegalArgumentException(fullFileName + " is a directory, please provide a single file name, or use the FileUploadSample to upload directories.");
}
else
{
client.uploadToBlobAsync("payments", inputStream, streamLength, new FileUploadStatusCallBack(), null);
}
Log.i("IoT App","File upload started with success");
Log.i("IoT App","Waiting for file upload callback with the status...");
}
catch (Exception e)
{
Log.e("IoT App","Exception while sending event: " + e.getMessage());
}
}
protected class FileUploadStatusCallBack implements IotHubEventCallback
{
public void execute(IotHubStatusCode status, Object context)
{
Log.i("IoT App","IoT Hub responded to file upload operation with status " + status.name());
TextViewControl.log("IoT Hub responded to file upload operation with status " + status.name());
}
}
我有这个文件 payments.json
设备(仿真器)中。
希望能得到帮助