Page 1 of 2

Getting image URL from Tiggzi Database

Posted: Thu Apr 11, 2013 5:27 pm
by CarmeloMilian

Hi, First of all, thanks for you help these days!

I am trying to have a list of items pulled from the Tiggzi Server that will include some fields and an image.

I am able to post the items to the server, and upload the image to the Files Tiggzi database.

However, when getting my items back from the server to the app I am able to get all fields but have no idea how to pull the images into the specific record. I know how to pull the image into the app with file get, but I dont know how to get the image name so that I can get the correct image to its specific record.

How can I get the image server url right away after uploading so that I can save it to the record?


Getting image URL from Tiggzi Database

Posted: Thu Apr 11, 2013 6:43 pm
by Maryna Brodina

Hello! REST service which is used for uploading files to Tiggzi DB has two response parameters: "filename" and "fileurl". If you followed our tutorial http://docs.tiggzi.com/tutorials/uplo... then you would need to change one part to save image URL to 'db_file_url' localStorage variable:
In section "Uploading files to Tiggzi database" (http://docs.tiggzi.com/tutorials/uplo...) there is the code:

codesuccess: function(data) {
// OPTIONAL, this is the file name under which the image was stored in database....
// localStorage.setItem('db_file_name', file.name);
},/code

replace it with the following:

codesuccess: function(data) {
// OPTIONAL, this is the file name under which the image was stored in database....
localStorage.setData('db_file_url', data.fileurl);
},/code


Getting image URL from Tiggzi Database

Posted: Thu Apr 11, 2013 9:09 pm
by CarmeloMilian

Thanks,
Once I do this I want to put that variable (with file url) content onto the Tiggzi image I called image.

Here is how I am trying to do it, but getting ...ReferenceError: db_file_name is not defined

success: function(data) {

Code: Select all

         // OPTIONAL, this is the file name under which the image was stored in database.... 
         localStorage.setItem('db_file_name', data.fileurl); 
         Tiggzi("image").val = localStorage.getItem(db_file_name); 

      }, 

I know I am doing something wrong in the syntax, but have tried many ways keep getting the error.


Getting image URL from Tiggzi Database

Posted: Fri Apr 12, 2013 5:44 am
by Maryna Brodina

Hi, instead of codeTiggzi("image").val = localStorage.getItem(db_file_name); /code use codeTiggzi("image").val = localStorage.getItem("db_file_name"); /code


Getting image URL from Tiggzi Database

Posted: Fri Apr 12, 2013 4:07 pm
by CarmeloMilian

Hi Marina, I did are you recommended and I can see that when i do a request for the record it comes now with the correct liink. I have attached that result to the form image Asset, however the image does not show. As you can see image has the correct data.

ParamsHeadersResponseJSONCookies

[{"id":"51682c50e4b055aafd1f2788","ItemOwner":"cmilian","SerialNumber":"007","Reward":"$10000000","State":"Florida","Image":"https://api.tiggzi.com/rest/1/db/file... What?","ItemDescription":"I have a good Geeling","createdAt":"2013-04-12 08:46:24.359","_updatedAt":"2013-04-12 08:46:24.359"}]

The Image Item only has Asset and Visible properties. Is there a Src?


Getting image URL from Tiggzi Database

Posted: Fri Apr 12, 2013 4:18 pm
by CarmeloMilian

I just realize that the image link I am saying is...
4bed4b5c-75df-42b9-88fd-ad369f1ce122.me.jpg

but the one on the file in database is...
22d50b98-9fab-4f03-87d2-4caadd1001e8.me.jpg

Why am I getting two different file names?


Getting image URL from Tiggzi Database

Posted: Fri Apr 12, 2013 4:52 pm
by Kateryna Grynko

The URL you get after file is downloaded to database can't be used as "SRC" attribute for Image component.

To get image data you would need to create Rest Service where as URL will be image address you get before and two additional parameters:

  • header Request parameter "X-Tiggzi-Database-Id" with value Database ID

  • request parameter "encoded" with value "base64" to make file data be coded in BASE64 format.

    For now, this Rest Service returns incorrect data. This will be fixed after next Tiggzi release.


Getting image URL from Tiggzi Database

Posted: Fri Apr 12, 2013 6:00 pm
by CarmeloMilian

ok, so that does it for getting an image, but I need this to be on each record when a list is pulled. this is my approach.

  1. Get Image with selector. (Followed tutorial)

  2. On Image Upload to file database and get the image URL and save it to a local variable.

  3. Save that image URL to local variable on to the record image field.

  4. Upload record.

    the record should be on the collection with the image field and the URL. When I pull that record I should be able to see the image.

    Is there an better way to do this. This way its not working for me.


Getting image URL from Tiggzi Database

Posted: Fri Apr 12, 2013 8:47 pm
by Kateryna Grynko

Hi Carmelo,

Sorry for the delay. You can get image from database using Rest Service only. There is no direct URL for image. What's wrong with using Rest Service?


Getting image URL from Tiggzi Database

Posted: Fri Apr 12, 2013 8:56 pm
by CarmeloMilian

I need to attach the image file to the belonging record when retrieving records. Not just download an image.

See the files are not attached to collections. I need to relate them in a way so that I can get the right image when i get a query records from collection.