Azure IoT는 MQTT나 AMQP 같은 여러 프로토콜을 사용하여 데이터를 보낼 수 있어요. 하지만 메시지 크기가 너무 큰 경우 Azure 서버에 파일을 업로드해야 해요. 이 문제를 해결하기 위해 IoT 허브는 허브와 미리 구성된 Blob 컨테이너 및 Azure 스토리지 계정에 대해 업로드별로 SAS(Shared Access Signature) URI를 제공하여 연결된 디바이스의 파일 업로드를 지원해요.
sgcWebSockets 2023.8.0부터 Azure IoT 클라이언트를 사용하여 파일을 업로드할 수 있어요. 인증서와 SAS 모두 지원되는 인증 방법이에요.
파일 업로드에 대한 자세한 내용은 다음 링크를 참고해요:
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-file-upload
인증서를 사용한 파일 업로드
먼저 Azure 계정에서 인증서를 구성한 다음 Azure IoT 클라이언트 컴포넌트에서 인증서 및 키 파일 경로를 설정해요. UploadFile 메서드를 호출하여 파일 이름 경로에서 파일을 업로드해요.
oClient := TsgcIoTAzure_MQTT_Client.Create(nil);
Try
oClient.Certificate.CertFile := 'cert.pem';
oClient.Certificate.KeyFile := 'key.pem';
oClient.Certificate.Enabled := True;
oDialog := TOpenDialog.Create(nil);
Try
if oDialog.Execute then
oClient.UploadFile(oDialog.FileName);
Finally
oDialog.Free;
End;
Finally
FreeAndNil(oClient);
End;
SAS를 사용한 파일 업로드
먼저 Azure IoT 클라이언트 컴포넌트에서 비밀 키를 구성해요. UploadFile 메서드를 호출하여 파일 이름 경로에서 파일을 업로드해요.
oClient := TsgcIoTAzure_MQTT_Client.Create(nil);
Try
oClient.SAS.SecretKey := 'your-secret-key';
oClient.SAS.KeyName := 'key-name';
oClient.SAS.Enabled := True;
oDialog := TOpenDialog.Create(nil);
Try
if oDialog.Execute then
oClient.UploadFile(oDialog.FileName);
Finally
oDialog.Free;
End;
Finally
FreeAndNil(oClient);
End;
