I use the GEE API in a Python environment and I want to upload numerous small image to my local machine. I try to implement the solution suggested here. Before upgrading my code I wanted to do some test in EE code editor but I cannot make it work.

So I tried to use the ee method getDownloadUrl to retrieve multiband images on very small surface using the following code:

function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)

  return image.updateMask(mask).divide(10000);

var aoi = ee.FeatureCollection('users/bornToBeAlive/FRA_Grid_2')
var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterDate('2020-01-01', '2020-01-30')
  // Pre-filter to get less cloudy granules.

var visualization = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],

//clip the dataset on the aoi 
var clip = dataset.mean().clip(aoi)

// get the first tile 
Map.addLayer(clip, visualization, 'S2')
Map.addLayer(aoi.first().geometry(), {}, "france")

The displayd image is very snowy but I manage to see things.

now to upload this image I want to get a downloadable link:

var link = clip.select(['B4', 'B3', 'B2']).getDownloadURL({
    'name': 'toto',
    'region': aoi.first().geometry(),
    'filePerBand': false


Unfortunately the link I get is giving me an image that is not scaled properly (the square is way too big) and I only get the same value for each pixel on each band.

Did I do something wrong? Does anyone knows how to use this function?


In the proposed code, you forgot the scale parameter.

here is a proper implementation for at 10 meters for sentinel 2 data :

var link = clip.select(['B4', 'B3', 'B2']).getDownloadURL({
    'name': 'toto',
    'region': aoi.first().geometry(),
    'filePerBand': false,
    'scale': 10


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.