Skip to content

trying to make it client side #359

@badoubadou

Description

@badoubadou

Hi,
I'm trying to translate it to react. I manage to make the first part with axios.

axios.post('https://api.cesium.com/v1/assets', {
      name: selectedFile.name,
      description: '',
      type: '3DTILES',
      options: {
        position:[ 2.29, 48.85, 0.1],
        sourceType: srcType
      }
    },{
      headers: { Authorization: `Bearer ${accessToken}` }
    })
    .then(response => sendtos3(response))
    .catch(function (error) {
      console.log(error);
    });`

Then my sendtos3 function is like this :

async function sendtos3(response){
    const uploadLocation = response.data.uploadLocation;
    const s3 = new AWS.S3({
      apiVersion: '2006-03-01',
      region: 'us-east-1',
      signatureVersion: 'v4',
      endpoint: uploadLocation.endpoint,
      credentials: new AWS.Credentials(
        uploadLocation.accessKey,
        uploadLocation.secretAccessKey,
        uploadLocation.sessionToken)
    });
    const params = {
      Body: selectedFile,
      Bucket: uploadLocation.bucket,
      Key: selectedFile.name
    };
    await s3.upload({
      Body: selectedFile,
      Bucket: uploadLocation.bucket,
      Key: selectedFile.name
    }).on('httpUploadProgress', function (progress) {
      console.log(`Upload: ${((progress.loaded / progress.total) * 100).toFixed(2)}%`);
    }).promise();
  } `

But I always get a : Failed to load resource: the server responded with a status of 403 (Forbidden).
When I check my credential, every thing seam to be ok.


Edited by javagl for code formatting

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions