C# File Browser using YetiShare API

dgogoasa

Member
Jul 26, 2018
32
6
8
I have developed a GUI File Browser in C# using the YetiShare API. So far I can Browse the files and folders and I can download files. I can also browse all the properties of folders and files.
1. Would be good if the elements of the nodes (folder, files) had some kind of description.
2, I need some help with UPLOADING a file. The admin API test works OK but the documentation lacks some specification. I am sure that somewhere in the call I need to provide a file stream for the server to hook into and stream my file in... but it is not clear what the server is expecting. Using C# I create a MultipartFormDataContent and I provide all the necessary parameters and a file stream... I can see the file gets streamed up (bandwidth monitor) and it takes a while to finish - just like the file is streamed up . . . but at the end I get the error "Did not receive uploaded file." . . . and the file IS NOT present in the folder i selected it to be in.

I am pretty advanced in developing this File Browser and I could implement all the API calls but I am stuck in file_upload.

Help would be appreciated.
 
  • Like
Reactions: singfa

dgogoasa

Member
Jul 26, 2018
32
6
8
For all interested . The C# browser is all done with all the functionality that I need for my future library. The windows GUI can be used to browse files and folder get extended info, upload, download and delete files. This is all that I need.

Next, I will move to code the client in Android which will read the files that the Windows app will create... So far so good!

Once again Thank you Adam for your patience and support.
 
  • Like
Reactions: singfa

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
I have developed a GUI File Browser in C# using the YetiShare API. So far I can Browse the files and folders and I can download files. I can also browse all the properties of folders and files.
1. Would be good if the elements of the nodes (folder, files) had some kind of description.
2, I need some help with UPLOADING a file. The admin API test works OK but the documentation lacks some specification. I am sure that somewhere in the call I need to provide a file stream for the server to hook into and stream my file in... but it is not clear what the server is expecting. Using C# I create a MultipartFormDataContent and I provide all the necessary parameters and a file stream... I can see the file gets streamed up (bandwidth monitor) and it takes a while to finish - just like the file is streamed up . . . but at the end I get the error "Did not receive uploaded file." . . . and the file IS NOT present in the folder i selected it to be in.

I am pretty advanced in developing this File Browser and I could implement all the API calls but I am stuck in file_upload.

Help would be appreciated.
Thanks for the feedback.

1) This should be easy to add, I'll include it in the next release.
2) Does your next post mean you've resolved this one? :) Or are you still having issues?

Thanks,
Adam.

#yetisharerfcs
 

dgogoasa

Member
Jul 26, 2018
32
6
8
Thanks for the feedback.

1) This should be easy to add, I'll include it in the next release.
2) Does your next post mean you've resolved this one? :) Or are you still having issues?

Thanks,
Adam.

#yetisharerfcs
All done and functional.

Thank you for support.
 
  • Like
Reactions: adam

sukhman21

Member
YetiShare User
YetiShare Supporter
Jan 26, 2015
508
3
18
lol and i am still stuck at upload API, got everything else to work fine no issues. Glad someone got upload API working... Do you mind helping me out on this upload CURL API ? I have tried every possibility and looked up curl file upload API's etc but no luck so far. I had given up on it lol.
 

dgogoasa

Member
Jul 26, 2018
32
6
8
I am sorry my language is C# and even that is "as a second language" and I can't help you with curl.
The only thing that may be helpful that is not clear in the documentation is that you need to provide a files stream, or any other stream that can be connected to your file. The file name that you provide is only used by the API server to store that data under that name not to really upload it. To upload it the API server needs a multi-part data form to be passed on. In C# I use a MultipartFormDataContent like this:
==============
var values = new Dictionary<string, string>
{
{ "access_token", authorize.data.access_token},
{ "account_id", authorize.data.account_id},
{ "folder_id", folder_id},
};

MultipartFormDataContent form = new MultipartFormDataContent();


form.Add(new StringContent(authorize.data.access_token), "access_token");
form.Add(new StringContent(authorize.data.account_id), "account_id");
form.Add(new StringContent(folder_id), "folder_id");
FileStream fstream = new FileStream(file_path, FileMode.Open);
StreamContent content = new StreamContent(fstream);
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "upload_file",
FileName = fileName
};
form.Add(content);
==============
If you can translate the principle to your preferred language that should do it...
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
lol and i am still stuck at upload API, got everything else to work fine no issues. Glad someone got upload API working... Do you mind helping me out on this upload CURL API ? I have tried every possibility and looked up curl file upload API's etc but no luck so far. I had given up on it lol.
I'll see if I can make up some examples to make this a bit clearer. Are you using pure Curl or PHP with Curl?
 

dgogoasa

Member
Jul 26, 2018
32
6
8
Thanks for the feedback.

1) This should be easy to add, I'll include it in the next release.
2) Does your next post mean you've resolved this one? :) Or are you still having issues?

Thanks,
Adam.

#yetisharerfcs
Is there an approximate ETA to 1) - (that is next release)?
 

sukhman21

Member
YetiShare User
YetiShare Supporter
Jan 26, 2015
508
3
18
Thank you guys. i am not at all a pro at developing applications using API but will certainly give it a try. I started using the webDAV instead and that has been working fine no issues.
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
Is there an approximate ETA to 1) - (that is next release)?
The next release will likely be in about 4-6 weeks. Although there's already support in the admin area for file descriptions, so if you're happy editing them using the admin area you can patch support into the API. To patch it edit:

"\core\includes\api\v2\endpoint\file.api.php"

Find:
Code:
keywords, isPublic, uploadSource
It'll be part of the info() function. After add:
Code:
, description
So the whole sql statement will look like:
Code:
$fileDetails = $db->getRow('SELECT file.id, originalFilename AS filename, shortUrl, fileType, extension, fileSize, uploadedIP, uploadedDate, '
                . 'status AS file_status, visits AS downloads, lastAccessed, folderId, keywords, isPublic, uploadSource, description FROM file '
                . 'WHERE file.id = :file_id AND userId = :user_id LIMIT 1', array('user_id' => (int) $this->request['account_id'], 'file_id' => (int) $this->request['file_id']), PDO::FETCH_ASSOC);
That should get it working on the /file/info/ endpoint.
 

dgogoasa

Member
Jul 26, 2018
32
6
8
The next release will likely be in about 4-6 weeks. Although there's already support in the admin area for file descriptions, so if you're happy editing them using the admin area you can patch support into the API. To patch it edit:

"\core\includes\api\v2\endpoint\file.api.php"

Find:
Code:
keywords, isPublic, uploadSource
It'll be part of the info() function. After add:
Code:
, description
So the whole sql statement will look like:
Code:
$fileDetails = $db->getRow('SELECT file.id, originalFilename AS filename, shortUrl, fileType, extension, fileSize, uploadedIP, uploadedDate, '
                . 'status AS file_status, visits AS downloads, lastAccessed, folderId, keywords, isPublic, uploadSource, description FROM file '
                . 'WHERE file.id = :file_id AND userId = :user_id LIMIT 1', array('user_id' => (int) $this->request['account_id'], 'file_id' => (int) $this->request['file_id']), PDO::FETCH_ASSOC);
That should get it working on the /file/info/ endpoint.

OK. That was simple enough and I can get that "description" back trough the API using file_info.

BUT... Now to complete the circle that description should also be set (also) trough the API. Most appropriate (I think) as part of the upload file. So that when somebody uploads a file they can set at the same time a description for it.

Don't get me wrong. I think that the capability to set that "description" is usable, but not as usable if one can set it trough the API.
 
Last edited:

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
Sure, I understand. I've logged it for review to include in the next release. If it's available before then I'll update here.
 

dgogoasa

Member
Jul 26, 2018
32
6
8
lol and i am still stuck at upload API, got everything else to work fine no issues. Glad someone got upload API working... Do you mind helping me out on this upload CURL API ? I have tried every possibility and looked up curl file upload API's etc but no luck so far. I had given up on it lol.

Some curl examples of using this API:
parameters
access_token=ha93FNTGZyfyr5G5ymrFQ7Az8V4SntcEDlHi9BZ9aeHBjoHSK8xBg8ap4fhsIu6lPODZqD8BRQdbeU4Z3CAjKLIP10hJuo5kcJjDmseeirpwmuwp67JQTsFUsWEXkKix
account_id=19
folder_id=3
upload_file=fileToUpload.zip

------------------------------ cURL
curl -X POST \
http://www.1droid.com.au/api/v2/file/upload \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Postman-Token: 44304e29-f433-42d8-9a0c-36190f5c1ab7' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F access_token=ha93FNTGZyfyr5G5ymrFQ7Az8V4SntcEDlHi9BZ9aeHBjoHSK8xBg8ap4fhsIu6lPODZqD8BRQdbeU4Z3CAjKLIP10hJuo5kcJjDmseeirpwmuwp67JQTsFUsWEXkKix \
-F account_id=19 \
-F folder_id=3 \
-F upload_file=fileToUpload.zip

------------------------- C(LibCurl)
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "http://www.1droid.com.au/api/v2/file/upload");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Postman-Token: dbaf5410-8586-45b1-bfee-f5a75a65c734");
headers = curl_slist_append(headers, "Cache-Control: no-cache");
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"access_token\"\r\n\r\nha93FNTGZyfyr5G5ymrFQ7Az8V4SntcEDlHi9BZ9aeHBjoHSK8xBg8ap4fhsIu6lPODZqD8BRQdbeU4Z3CAjKLIP10hJuo5kcJjDmseeirpwmuwp67JQTsFUsWEXkKix\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"account_id\"\r\n\r\n19\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"folder_id\"\r\n\r\n3\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"upload_file\"\r\n\r\nfileToUpload.zip\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");

CURLcode ret = curl_easy_perform(hnd);

--------------------- PHP Curl
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "http://www.1droid.com.au/api/v2/file/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"access_token\"\r\n\r\nha93FNTGZyfyr5G5ymrFQ7Az8V4SntcEDlHi9BZ9aeHBjoHSK8xBg8ap4fhsIu6lPODZqD8BRQdbeU4Z3CAjKLIP10hJuo5kcJjDmseeirpwmuwp67JQTsFUsWEXkKix\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"account_id\"\r\n\r\n19\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"folder_id\"\r\n\r\n3\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"upload_file\"\r\n\r\nfileToUpload.zip\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/x-www-form-urlencoded",
"Postman-Token: a355176e-3b67-4702-ac80-99fefff62a77",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

---------------------------- HTTP
POST /api/v2/file/upload HTTP/1.1
Host: www.1droid.com.au
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache-Control: no-cache
Postman-Token: 42a2014b-bee5-48f2-baea-2e73ae048a05

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="access_token"

ha93FNTGZyfyr5G5ymrFQ7Az8V4SntcEDlHi9BZ9aeHBjoHSK8xBg8ap4fhsIu6lPODZqD8BRQdbeU4Z3CAjKLIP10hJuo5kcJjDmseeirpwmuwp67JQTsFUsWEXkKix
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="account_id"

19
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="folder_id"

3
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="upload_file"

fileToUpload.zip
------WebKitFormBoundary7MA4YWxkTrZu0gW--
 

sukhman21

Member
YetiShare User
YetiShare Supporter
Jan 26, 2015
508
3
18
Thanks very much for the examples. I will continue on my project again and will give this a try.