0

i am using django rest framework.problem i am facing is that data in to form to arrray is comming from external api i convert it to tiff formate.How can i store this tiff file in 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()

thru this code tiff file in genrating and save as a ndviimage.tiff file in locally directory.

1 Answers1

0

bit late, but you can use Cloudinary uploader like this:

   from cloudinary.uploader import upload

   response = upload("ndviimage.tif")

The response is a dictionary like this:

{
 '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
}

I tested it for GeoTiff and it uploaded correctly.

Ali
  • 626
  • 1
  • 11
  • 29