Recently Windows 10 IoT Core Build 14393 is coming, but still without PiCamera support, WTF. So I can only choose Linux for my project. When I was using Windows, I use C# + Azure SDK to upload photos to Microsoft Azure. So how to do it on Linux?
After some research, here's how to do it.
My system is Raspbian Linux. First, we need to install Azure SDK in SSH Terminal:
sudo pip install --pre azure
Remember to execute the command as "sudo". Or you will not have permission to install it.
After installation, Python will support Azure. You will need an Azure storage account, such as mine, called "edirpi3", with a container named "webcamupload" in it.
Then, create a new py file:
sudo nano testazureblob.py
Acccessing Azure Container from python:
from azure.storage.blob import BlockBlobService block_blob_service = BlockBlobService(account_name='edirpi3', account_key='YOURKEY')
the "account_name" and "account_key" is in your azure portal:
To upload file:
from azure.storage.blob import ContentSettings block_blob_service.create_blob_from_path( 'webcamupload', 'firstblood.jpg', 'image1.jpg', content_settings=ContentSettings(content_type='image/jpeg'))
To take picture:
import picamera camera = picamera.PiCamera() camera.capture('image1.jpg')
Integrate those two functions, we get the code for upload picture to Azure Blob:
from azure.storage.blob import BlockBlobService from azure.storage.blob import ContentSettings import picamera camera = picamera.PiCamera() camera.capture('image1.jpg') block_blob_service = BlockBlobService(account_name='edirpi3', account_key='YOURKEY') block_blob_service.create_blob_from_path( 'webcamupload', 'firstblood.jpg', 'image1.jpg', content_settings=ContentSettings(content_type='image/jpeg'))
Execute python file with "sudo python":
If everything is good, you will be able to see the picture in Azure portal:
Phodal
棒棒的,收到这期的《物联网周报》里。
zonghua
天了噜,阿迪王竟然写 Python
asbmta
Hello, Edi. I had a problem trying to follow this tutorial. Whenever I run the code, it states that the azure.storage module cant be found, with something like this: "ImportError: No module named 'azure.storage'" I've tried reinstalling azure pip3 modules; and it seems that all is in order, since the required files are inside dist-packages. Unfortunately, it showed the same error after these changes. I've also tried finding a solution in other forums, but nothing matches. What can I do? Thanks in advance.