如何使用django-rest框架将tiff文件上传到cloudinary



我使用的是django rest framework。我面临的问题是,要形成arrray的数据来自外部api,我将其转换为tiff甲酸盐。我如何将这个tiff文件存储在cloudnary中。

ndvi_image = rasterio.open(
'ndviimage.tif', 'w', driver='GTiff', height=500, width=500, count=1, dtype='float32', crs='EPSG:4326', transform=rasterio.transform.from_bounds(*box2, 500, 500))
ndvi_image.write(image, 1)
ndvi_image.close()

通过genrating中的这个代码tiff文件,并保存为本地目录中的ndviimage.tiff文件。

有点晚,但您可以像这样使用Cloudinary上传器:

from cloudinary.uploader import upload
response = upload("ndviimage.tif")

响应是这样的字典:

{
'api_key': 'xxxxxx',
'asset_id': 'xxxxxx',
'bytes': 32802,
'created_at': '2022-10-13T08:35:00Z',
'etag': 'xxxxxx',
'folder': '',
'format': 'tiff',
'height': 70,
'original_extension': 'tif',
'original_filename': 'ndviimage',
'pages': 1,
'placeholder': False,
'public_id': 'qzpmeqgvguyqptfjh5pu',
'resource_type': 'image',
'secure_url': 'https://res.cloudinary.com/xxxx/image/upload/v1665650100/qzpmeqgvguyqpttiff',
'signature': 'xxxx',
'tags': [],
'type': 'upload',
'url': 'http://res.cloudinary.com/xxxx/image/upload/v1665650100/qzpmeqgvguyqptfjh5pu.tiff',
'version': 1665650100,
'version_id': 'xxxx',
'width': 109
}

我为GeoTiff测试了它,它上传正确。

最新更新