Git Product home page Git Product logo

Comments (9)

danielsequeira avatar danielsequeira commented on July 25, 2024 1

Hey @Huljo. At the moment this is not possible, you can only upload using the file itself. @osener @GuilhermeSCP is this something we could have a look into?

from bynder-js-sdk.

ozanmakes avatar ozanmakes commented on July 25, 2024 1

@Huljo thank you for the test case, you're absolutely right. We will release a fix as soon as possible.

Have a great weekend!

from bynder-js-sdk.

GuilhermeSCP avatar GuilhermeSCP commented on July 25, 2024

Hey @Huljo!
Indeed it should be possible, the SDK should be able to understand what type of file you're passing and parse it accordingly. Let us know if something doesn't work.

from bynder-js-sdk.

Huljo avatar Huljo commented on July 25, 2024

Hey @GuilhermeSCP and @danielsequeira,
I didn't found any example about it so I tryed this way (based on uploadFile example here) :

const fs = require('fs');
const path = require('path');
const Bynder = require('@bynder/bynder-js-sdk').default;
const bynderConfig = {
    consumer: {
        public: '********',
        secret: '********',
    },
    accessToken: {
        public: '********',
        secret: '********',
    },
    "baseURL": "https://********.getbynder.com/api/"
};

const bynder = new Bynder(bynderConfig);
bynder.getBrands()
    .then((data) => {
        const brand = data[0];
        const file = `${__dirname}/testasset.png`;
        return bynder.uploadFile({
            filename: path.basename(file),
            body: fs.createReadStream(file),
            data: {
                brandId: brand.id,
                name: 'test asset'
            }
        });
    })
    .then(console.log)
    .catch((error) => {
        console.error(error);
    });

It throw me an error related to the file length :

{ status: 0,
  message: 'The upload length is not valid or it was not specified properly' }

Where can I find the documentation about this method ?

Thank you guys for the support.

from bynder-js-sdk.

GuilhermeSCP avatar GuilhermeSCP commented on July 25, 2024

Just took a new look and you're right, that case is not entirely covered, I'll reopen and escalate the issue. Thanks for letting us know!

from bynder-js-sdk.

Huljo avatar Huljo commented on July 25, 2024

I added a property length to uploadFile options ( bynder.uploadFile({..., length:[int], ...}) ). The upload is working now but I have to get the total file length before using uploadFile.

Not sure if it is uploading every stream chunks on the fly or if it's waiting the entire file to push chunk separately. (Since Im working on AWS Lambdas I cant work with FS so I need the first behavior)

from bynder-js-sdk.

ozanmakes avatar ozanmakes commented on July 25, 2024

@Huljo we've investigated possibilities for allowing this, but unfortunately our uploads API has to know the number of chunks ahead of time. I'm afraid we can't address this until Bynder gets a new API for uploads. We'll keep you posted if we hear about any plans for this.

For now, I suggest getting the length of your source file yourself. Since how to do this depends on the type of the stream, I don't think we'll implement this in the SDK.

You mentioned you won't be using fs, but if you can read the file size via the ContentLength property of S3.getObject response or content-length response header of an HTTP stream it should do the trick.

Let us know if you have further questions.

from bynder-js-sdk.

Huljo avatar Huljo commented on July 25, 2024

Thank you for the quick reply @osener .
Using content-length from S3.getObject do the trick for me.

Everything looks ready to handle stream data using the SDK. There is just a lack of information about how to use it. Maybe you should plan to create an example using length property in uploadFile options or a short documentation.

from bynder-js-sdk.

ozanmakes avatar ozanmakes commented on July 25, 2024

Noted 👍. Happy to hear you got it working!

from bynder-js-sdk.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.