Failed to use Mapbox "Create Download" api to load data file

I am trying to upload my local json file to mapbox using upload api . I follow these steps:

  • Get S3 credentials to create a file
  • Use an S3 client, such as the AWS SDK, to upload a file to S3 using these credentials
  • Create a download using a phased file URL
  • Get download status when it is processed as a tile
  • After the download is complete, use the item set identifier, for example, you would use any other item set.

I followed steps 1 and 2, but getting the following error in steps 3:

The remote server returned an error: (422) Unprocessing organization.

Below is my code (step 1):

class Program { static void Main(string[] args) { var getCredsUrl= @"https://api.mapbox.com/uploads/v1/{my_mapbox_username}/credentials?access_token={my_mapbox_token}"; var request = (HttpWebRequest)WebRequest.Create(getCredsUrl); request.AutomaticDecompression = DecompressionMethods.GZip; using (var response = (HttpWebResponse)request.GetResponse()) using (var stream = response.GetResponseStream()) if (stream != null) using (var reader = new StreamReader(stream)) { var res = reader.ReadToEnd(); var mbS3Credentials = JObject.Parse(res); var accessKeyId = (string)mbS3Credentials["accessKeyId"]; var bucket = (string)mbS3Credentials["bucket"]; var key = (string)mbS3Credentials["key"]; var secretAccessKey = (string)mbS3Credentials["secretAccessKey"]; var sessionToken = (string)mbS3Credentials["sessionToken"]; var serviceUrl = (string)mbS3Credentials["url"]; var localFilePath = "c:\\users\\saurabh\\documents\\visual studio 2015\\Projects\\MapboxTileSetUpload\\MapboxTileSetUpload\\data\\localFile.json"; var amazonS3Uploader = new AmazonS3Uploader(accessKeyId, secretAccessKey, sessionToken, serviceUrl + "localFile.json"); var suucess = amazonS3Uploader.UploadFile(localFilePath, bucket, key); if (suucess) { string createUploadUrl = @"https://api.mapbox.com/uploads/v1/{my_mapbox_username}?access_token={my_mapbox_token}"; string tileSet = "{my_mapbox_username}.myTileSet"; string s3BucketFileUrl = serviceUrl + "/localFile.json"; string name = "example-dataset"; var createUpload = new MapboxUploader(createUploadUrl, tileSet, s3BucketFileUrl, name); createUpload.CreateUpload(); } } } } 

Download to Amazon S3 (step 2):

 public class AmazonS3Uploader { private readonly AmazonS3Client _s3Client; public AmazonS3Uploader(string accessKeyId, string secretAccessKey, string sessionToken, string serviceUrl) { var s3Config = new AmazonS3Config { ServiceURL = serviceUrl, RegionEndpoint = RegionEndpoint.USEast1, ForcePathStyle = true, }; _s3Client = new AmazonS3Client(accessKeyId, secretAccessKey, sessionToken, s3Config); } public bool UploadFile(string filePath, string s3BucketName, string key) { //save in s3 var s3PutRequest = new PutObjectRequest { FilePath = filePath, BucketName = s3BucketName, Key = key, CannedACL = S3CannedACL.PublicRead }; s3PutRequest.Headers.Expires = new DateTime(2020, 1, 1); try { PutObjectResponse s3PutResponse = this._s3Client.PutObject(s3PutRequest); if (s3PutResponse.HttpStatusCode.ToString() == "OK") return true; else return false; } catch (Exception ex) { //handle exceptions return false; } } } 

Create a Mapbxo download (Step 3: I get an error here):

 public class MapboxUploader { private readonly string _createUploadUrl; private readonly string _tileSet; private readonly string _s3Fileurl; private readonly string _name; public MapboxUploader(string createUploadUrl, string tileSet, string s3BucketFileUrl, string name) { _createUploadUrl = createUploadUrl; _tileSet = tileSet; _s3Fileurl = s3BucketFileUrl; _name = name; } public async Task<bool> HttpClient() { using (var client = new WebClient()) { client.BaseAddress = new Uri(this._createUploadUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Dictionary<string, string> data = new Dictionary<string, string>() { { "tileset", this._tileSet }, { "url", this._s3Fileurl }, { "name", this._name } }; var postData = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json"); try { var response = await client.PostAsync(this._createUploadUrl, postData); return true; } catch (Exception ex) { return false; } } } } 

My guess: I cannot upload files to the S3 bucket in step 2. Here is the answer from step 2: enter image description here

And in step 3 I get a non-processor error, with the error message Unable to access the URL . Therefore, I think my S3 bucket file is not available.

enter image description here

When I try to enter the URL of the downloaded S3 file into the browser, I get access denied:

enter image description here

Access to network access token areas: enter image description here

What exactly am I missing here.

+5
source share

Source: https://habr.com/ru/post/1265091/


All Articles