How to transfer files from "Files" section to "Data"->"app tables"->"images"

Hello, how to transfer files from “Files” section to “Data”->“app tables”->“images” so that for each file would be created a new row in the “images” table?

Screenshot_83.png

Btw I know, that I can do it using “Data browser”->“Add new” one by one, the problem is that there are thousands of images, so it would take ages to add them one by one.

How about writing code that would do that? The Files API has the “directoryListing” function so you can get a list of files, then for every file, make a request to create an object…

actually, I’m stuck in finding what code would be suitable for my case, that’s why I posted this question.

is there any example of how to do that?
btw here are exported csv files, I noticed in another topic it was required.

maps.csv (11.65kB)

I guess it’s https://backendless.com/documentation/files/php/file_directory_listing.htm

Where should I paste this code? To the REST console?

$file_list = Backendless::$Files->listing( "/web", "*.html", true )->getAsArrays();
  foreach ( $file_list as $file) {
      echo "File name" . $file['name'];
  }

the solution above is for java project and I rather need it to be done in the REST console

I guess it is somewhere here?
https://backendless.com/documentation/files/rest/file_directory_listing.htm

Yes, that’s the REST API for getting a listing for a directory.

where should I paste this code?

Request Headers:

application-id: app-id-value
secret-key: secret-key-value
Content-Type: application/json
application-type: REST
user-token: user token value

Example:

curl 
-H application-id:application-id-value-from-console
-H secret-key:secret-key-value-from-console 
-H Content-Type: application/json 
-H application-type:REST 
-X GET 
-v "https://api.backendless.com/v1/files/web?pattern=*.html&sub=true"

You need to use the request headers when you make your REST requests.

hello, what may be the problem?

there must be some mistake in curl ?

Screenshot_89.png

you should write a command in one line,
the example contains break lines, so you should delete it. for example

curl -H application-id:<your-app-id> -H secret-key:<your-rest-secret-key> -H Content-Type:application/json -H application-type:REST -X POST -v 'https://api.backendless.com/v1/users/register' -d '{"email":"john.smith@foo.bar", "name":"John", "password":"123456seven"}'

also this example is for unix system, it may have small difference in a syntax for different os.

I deleted break lines, also it turned out that windows doesn’t apostrophe like ’ so I changed all apostrophes to " , but I still get result that is not expected.
I guess the problem is in the first three lines? how to fix it?
"* Could not resolve host: application

  • Closing connection 0
    curl: (6) Could not resolve host: application"
curl -H application-id:7A3123D65F-111-0B5F-Fda8-431D0asdf6800 -H secret-key:ABadfD8-8612-6AF1-F21AF-54B9df12a90C00 -H Content-Type: application/json -H application-type:REST -X GET -v "[url=https://api.backendless.com/#maps/v1/data/media/?pattern=*.png&sub=true//]https://api.backendless.com/#maps/v1/data/media/?pattern=*.png&sub=true//"[/url];
* Could not resolve host: application
* Closing connection 0
curl: (6) Could not resolve host: application
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 149.56.79.124...
* Connected to api.backendless.com (149.56.79.124) port 443 (#1)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: C:\Program Files\cURL\bin\curl-ca-bundle.crt
 CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* NPN, negotiated HTTP1.1
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Unknown (67):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.backendless.com
* start date: Feb 8 00:00:00 2016 GMT
* expire date: Mar 13 23:59:59 2019 GMT
* subjectAltName: api.backendless.com matched
* issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
* SSL certificate verify ok.
> GET / HTTP/1.1
> Host: api.backendless.com
> User-Agent: curl/7.46.0
> Accept: */*
> application-id:7A73asda-1E36-012F-FF78-4314123B6800
> secret-key:ABDasdfD8-8612-6AF1-FFAF-1241231s990C00
> application-type:REST
>
< HTTP/1.1 200 OK
< Server: nginx/1.8.1
< Date: Tue, 04 Oct 2016 07:45:23 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 70
< Connection: keep-alive
< Expires: Thu, 01 Jan 1970 00:00:01 GMT
< Cache-Control: no-cache
< Cache-Control:: no-store, no-cache, must-revalidate, private
< Pragma:: no-cache
<
All works! c73b3f4621f067d64d52802f0b0f6d6b90c256c0 build id is 94386* Connection #1 to host api.backendless.com left intact

Where from did you get this URL - https://api.backendless.com/#maps/v1/data/media/?pattern=*.png&sub=true//"; ??

Hi Kirill

Are you sure, you need cURL for your script ?

When Mark suggested writing the code, he assumed writing it on a language most suitable for you (Java, JavaScript, Swift, PHP)

Just download corresponded Backendless SDK, and write a small application, which, using the SDK, makes an API calls to the server and performs Files transfer

You should use REST API only if Backendless doesn’t provide an SDK for your preferred language

Vitaly Vengrov,

It’s because I’m not developer and I start tilting when I see java code that I don’t understand. So that’s why I tried to find another way for solution of this task.

Sergey Chupov ,

https://backendless.com/documentation/files/rest/file_directory_listing.htm

Ok. This is impossible to achieve without writing the code.

And using a cURL utility also means putting its invocation into shell script

But the URL on screenshot is different from what you used.

Vitaly Vengrov ,
Why would this REST documentation excist at all if it’s impossible?
Sergey Chupov ,
It’s becuase I need to get list of png files (not html as in example)and they are stored in another folder, so that’s why I edited request
Request edited (fixed some typos):

curl -H
application-id: 7A73D65F-1E36-0B5F-FF78-431D03CB6800 -H secret-key: ABDB70D8-8612-6AF1-FFAF-54B95D990C00
-H Content-Type: application/json -H application-type:REST -X GET -v "[url=https://api.backendless.com/v1/data/media/maps/adventure/adventure/?pattern=*.png&sub=true//]https://api.backendless.com/v1/data/media/maps/adventure/adventure/?pattern=*.png&sub=true//[/url]"

Response:

root@docker-512mb-fra1-01:~#
curl -H application-id: 7A73D65F-1E36-0B5F-FF78-431D03CB680 -H secret-key:
ABDB70D8-8612-6AF1-FFAF-54B95D990C00 -H Conetent-Type: application/json -H
application-type:Rest -X GET -v
"https://api.backendless.com/v1/data/media/maps/adventure/adventure/?pattern=*.png&sub=true//"
* Rebuilt URL to:
7A73D65F-1E36-0B5F-FF78-431D03CB680/
* Hostname was NOT
found in DNS cache
* Could not resolve
host: 7A73D65F-1E36-0B5F-FF78-431D03CB680
* Closing connection 0
curl: (6) Could not
resolve host: 7A73D65F-1E36-0B5F-FF78-431D03CB680
* Rebuilt URL to:
ABDB70D8-8612-6AF1-FFAF-54B95D990C00/
* Hostname was NOT
found in DNS cache
* Could not resolve
host: ABDB70D8-8612-6AF1-FFAF-54B95D990C00
* Closing connection 1
curl: (6) Could not
resolve host: ABDB70D8-8612-6AF1-FFAF-54B95D990C00
* Hostname was NOT
found in DNS cache
* Could not resolve
host: application
* Closing connection 2
curl: (6) Could not
resolve host: application
* Hostname was NOT
found in DNS cache
*   Trying 149.56.79.124...
* Connected to
api.backendless.com (149.56.79.124) port 443 (#3)
* successfully set
certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS
handshake, Client hello (1):
* SSLv3, TLS
handshake, Server hello (2):
* SSLv3, TLS
handshake, CERT (11):
* SSLv3, TLS
handshake, Server key exchange (12):
* SSLv3, TLS
handshake, Server finished (14):
* SSLv3, TLS
handshake, Client key exchange (16):
* SSLv3, TLS change
cipher, Client hello (1):
* SSLv3, TLS
handshake, Finished (20):
* SSLv3, TLS change
cipher, Client hello (1):
* SSLv3, TLS
handshake, Finished (20):
* SSL connection using
ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*        subject: OU=Domain Control Validated;
OU=PositiveSSL Wildcard; CN=*.backendless.com
*        start date: 2016-02-08 00:00:00 GMT
*        expire date: 2019-03-13 23:59:59 GMT
*        subjectAltName: api.backendless.com
matched
*        issuer: C=GB; ST=Greater Manchester;
L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server
CA
*        SSL certificate verify ok.
> GET
/v1/data/media/maps/adventure/adventure/?pattern=*.png&sub=true// HTTP/1.1
> User-Agent:
curl/7.35.0
> Host: api.backendless.com
> Accept: */*
>
application-type:Rest
> 
< HTTP/1.1 404 Not
Found
* Server nginx/1.8.1
is not blacklisted
< Server:
nginx/1.8.1
< Date: Tue, 04 Oct
2016 14:20:28 GMT
< Content-Type:
text/html; charset=utf-8
< Content-Length:
1967
< Connection: keep-alive
< 
 
 
&lt;!DOCTYPE html&gt;
&lt;html&gt;
        &lt;head&gt;
                &lt;title&gt;Action not
found&lt;/title&gt;
                <link rel="shortcut
icon"
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAlFJREFUeNqUU8tOFEEUPVVdNV3dPe8xYRBnjGhmBgKjKzCIiQvBoIaNbly5Z+PSv3Aj7DSiP2B0rwkLGVdGgxITSCRIJGSMEQWZR3eVt5sEFBgTb/dN1yvnnHtPNTPG4PqdHgCMXnPRSZrpSuH8vUJu4DE4rYHDGAZDX62BZttHqTiIayM3gGiXQsgYLEvATaqxU+dy1U13YXapXptpNHY8iwn8KyIAzm1KBdtRZWErpI5lEWTXp5Z/vHpZ3/wyKKwYGGOdAYwR0EZwoezTYApBEIObyELl/aE1/83cp40Pt5mxqCKrE4Ck+mVWKKcI5tA8BLEhRBKJLjez6a7MLq7XZtp+yyOawwCBtkiBVZDKzRk4NN7NQBMYPHiZDFhXY+p9ff7F961vVcnl4R5I2ykJ5XFN7Ab7Gc61VoipNBKF+PDyztu5lfrSLT/wIwCxq0CAGtXHZTzqR2jtwQiXONma6hHpj9sLT7YaPxfTXuZdBGA02Wi7FS48YiTfj+i2NhqtdhP5RC8mh2/Op7y0v6eAcWVLFT8D7kWX5S9mepp+C450MV6aWL1cGnvkxbwHtLW2B9AOkLeUd9KEDuh9fl/7CEj7YH5g+3r/lWfF9In7tPz6T4IIwBJOr1SJyIGQMZQbsh5P9uBq5VJtqHh2mo49pdw5WFoEwKWqWHacaWOjQXWGcifKo6vj5RGS6zykI587XeUIQDqJSmAp+lE4qt19W5P9o8+Lma5DcjsC8JiT607lMVkdqQ0Vyh3lHhmh52tfNy78ajXv0rgYzv8nfwswANuk+7sD/Q0aAAAAAElFTkSuQmCC">
            &lt;style&gt;
                    html, body, pre {
                        margin: 0;
                        padding: 0;
                        font-family: Monaco,
'Lucida Console', monospace;
                        background: #ECECEC;
                    }
                    h1 {
                        margin: 0;
                        background: #AD632A;
                        padding: 20px 45px;
                        color: #fff;
                        text-shadow: 1px 1px
1px rgba(0,0,0,.3);
                        border-bottom: 1px
solid #9F5805;
                        font-size: 28px;
                    }
                    p#detail {
                        margin: 0;
                        padding: 15px 45px;
                        background: #F6A960;
                        border-top: 4px solid
#D29052;
                        color: #733512;
                        text-shadow: 1px 1px
1px rgba(255,255,255,.3);
                        font-size: 14px;
                        border-bottom: 1px
solid #BA7F5B;
                    }
                &lt;/style&gt;
        &lt;/head&gt;
        &lt;body&gt;
                &lt;h1&gt;Action not
found&lt;/h1&gt;
 
                &lt;p id=&quot;detail&quot;&gt;
                        For request 'GET
/v1/data/media/maps/adventure/adventure/?pattern=*.png&amp;sub=true//'
                &lt;/p&gt;
 
        &lt;/body&gt;
&lt;/html&gt;

So the problem is in line 3-16, I guess there are still typos in header request and I must put some " and ’ there in order to fix it.
Correct me if I am wrong.

Vitaly Vengrov,https://backendless.com/documentation/files/rest/file_directory_listing.htm