Watson Workspace will no longer be available after February 28, 2019. Learn more.

Developers

How can I send an image into a space by api?

Comments

6 comments

  • Avatar
    Miguel Estrada

    Currently uploading a file automatically creates an entry for it in the conversation associated to the space in which the file is uploaded.

    The API to upload files is here:

    https://developer.watsonwork.ibm.com/docs/api-reference/files

    It has example on the params:

    "Renders an image in the transcript with given dimensions (WIDTH)x(HEIGHT) in pixels, example ?dim=400x300"

     

    Here is a curl request.  Replace SPACE_ID with one for your space and the JWT_TOKEN_DATA with one corresponding to the identity/client executing the request:


    curl -X "POST" "https://api.watsonwork.ibm.com/v1/spaces/SPACE_ID/files?dim=300x100" \
    -H 'Content-Type: multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__' \
    -H 'Authorization: bearer JWT_TOKEN_DATA' \
    -H 'Accept: application/json' \
    -F "file="

     

  • Avatar
    跃 林

    curl -X "POST" "https://api.watsonwork.ibm.com/v1/spaces/5ad04166e4b098d8cef61930/files"  -H 'Content-Type: multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__'  -H 'Authorization: bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJsaW55dWVAemh1b3l1bS5pYm1jb2xsYWIuY29tIiwiZGlzcGxheU5hbWUiOiLot4Mg5p6XIiwicHJvdmlkZXJJZCI6IkJMVUVfSURfQVVUSF9QUk9WSURFUiIsInBlcm1pc3Npb25zIjpbIm9mZmVyaW5nX3ByZXZpZXciXSwic2NvcGUiOlsic2VhcmNoIiwiYXBwcm92YWwubWFuYWdlIiwicmVhZCIsInByaXZpbGVnZWRfY2xpZW50IiwiaWJtaWQiLCJydG0iLCJ3cml0ZSIsIm9mZmVyaW5nX3ByZXZpZXciXSwiaWQiOiJlZjYzZWNkNy04ZWZmLTRlYWQtYTlmYy0wNTNhNDNlMWZlMGYiLCJleHAiOjE1MjQwNTE0MDQsImp0aSI6ImRjZGNmMmQ4LTFmMDItNGJhOC1hY2IxLTcyNjhkY2EzYjU4ZiIsImNsaWVudF9pZCI6InRvc2NhbmEtd2ViLWNsaWVudC1pZCJ9.DhMUak4VW7Jp8yHIC99oOvWWwtkFIbccZBN-23hprEQFnIN1MYDVc4ubtoZKUfxYLaPHSpl26cnnDTPn8r-QaR4KaaFk_5WFDkFk1zOTrSriz__IaHeFPF9mRrLkJ0PFlizckETeQ_VyCTg_0Jh8yeSjlcxK2258R41lrChLEQXMxbueLf8j_Cr5KVA5U_57ESVg4diaWzUE_vACJGDGPD4Z_upjZ873ghNtuerkSstsR51w0TEOEq7MYlhcJHXYoNF18c7aIVyvEuwTDOuYpE0K0S4bPrIGwJGw8W70Ddp8J7jVY0Feka88D1P8qeRO2Wx5WP4oke6C8ulKp1mXMA'  -H 'Accept: application/json'  -F "file=https://ibm.box.com/shared/static/sx22ajsxmpmy14h5dclxa0u52semdx42.png"
    {"errorMessage":"UNKNOWN"}

    I got a UNKNOWN error, I'm sure the token is correct because no 401 error again.

  • Avatar
    Darren Cacy

    Some of us are working on an unofficial SDK for Workspace, and it has an API to send an image to a space. Check it out at https://github.com/van-ibm/watsonworkspace-sdk.

  • Avatar
    Miguel Estrada

    跃 林

    I think the issue with your query is that the last param... file= you are passing a URL vs the actual contents of the file.  We don't have an API that takes a URL as a source for the file content.  We assume you have the actual file contents.

    I just tested these little scripts which you can use after you set the JWT environment variable.  

    cat uploadimage.sh 

    echo Sending image $1 with dimensions $2 to space $3
    curl -X "POST" "https://api.watsonwork.ibm.com/v1/spaces/$3/files?dim=$2" \
         -H 'Content-Type: multipart/form-data; charset=utf-8'  \
         -H 'Accept: application/json' \
         -H 'Authorization: bearer  '$JWT \
         -F "file=@"$1

     

    and

    cat uploadfile.sh 

    echo Sending: $1 to space $2
    curl -X "POST" "https://api.watsonwork.ibm.com/v1/spaces/$2/files" \
         -H 'Content-Type: multipart/form-data; charset=utf-8'  \
         -H 'Accept: application/json' \
         -H 'Authorization: bearer  '$JWT \
         -F "file=@"$1

     

  • Avatar
    Bernd Gewehr

    It would be very helpful to find an ‚auto‘ value for the dim parameter. Otherwise you have to know the dimensions of the image while uploading which is often motet he case. Guessing dimensions leads to ugly pictures...

  • Avatar
    Darren Cacy

    The Workspace API appears to look for the "dim" and if it's not there it uploads the file as a regular old file...but if it's there it also shows the image of the file in the space.  So it seems to pivot on whether the dim value is there, which means it wants you (the developer) to tell it what to do.  It would seem the modification you are looking for is to tell Workspace "this is an image and I want you to calculate the dimensions", maybe by (as you suggest) putting dim=auto into the url.

    The SDK which I mentioned above will see if the file is an image and calculate the correct values if you do not supply them. If you are developing using nodejs, check it out!

Please sign in to leave a comment.