Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ipfs-images-php-client
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ipfs-images
ipfs-images-php-client
Commits
ca895f18
Commit
ca895f18
authored
Sep 07, 2017
by
Dmitry Nikulin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return download link instead of hash
parent
04f76205
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
AttachmentsClient.php
src/AttachmentsClient.php
+12
-5
No files found.
src/AttachmentsClient.php
View file @
ca895f18
...
...
@@ -10,6 +10,11 @@ class AttachmentsClient {
private
$baseUrl
;
private
$client
;
/**
* Creates a new client instance.
*
* @param string $baseUrl Base URL for attachment server API
*/
function
__construct
(
$baseUrl
)
{
$this
->
baseUrl
=
$this
->
ensureNotEndsWithSlash
(
$baseUrl
);
$this
->
client
=
new
Client
();
...
...
@@ -22,7 +27,7 @@ class AttachmentsClient {
*
* @param string $filename Path to file to be uploaded
*
* @return string
Hash of uploaded
file
* @return string
Download link for the
file
*/
public
function
uploadFromFile
(
$filename
)
{
$data
=
file_get_contents
(
$filename
);
...
...
@@ -35,14 +40,14 @@ class AttachmentsClient {
* @param string $file File data to be uploaded, stored in memory
* @param string $name (optional) Name of file to be passed to server
*
* @return string
Hash of uploaded
file
* @return string
Download link for the
file
*/
public
function
uploadFromMemory
(
$data
,
$name
=
'file'
)
{
$url
=
$this
->
getFullMethodUrl
(
'/ul'
);
$result
=
$this
->
sendPostRequestWithFile
(
$url
,
$data
,
$name
);
$json
=
json_decode
(
$result
,
true
);
return
$
json
[
'id'
]
;
return
$
this
->
getDownloadUrl
(
$json
[
'id'
],
$json
[
'filename'
])
;
}
// *** End of public API methods ***
...
...
@@ -51,6 +56,10 @@ class AttachmentsClient {
return
rtrim
(
$url
,
'/'
);
}
private
function
getDownloadUrl
(
$hash
,
$name
)
{
return
$this
->
baseUrl
.
'/dl/'
.
$hash
.
'/'
.
$name
;
}
private
function
getFullMethodUrl
(
$method
)
{
return
$this
->
baseUrl
.
$method
;
}
...
...
@@ -66,8 +75,6 @@ class AttachmentsClient {
]
]);
echo
$response
->
getBody
();
if
(
$response
->
getStatusCode
()
!==
200
)
{
$message
=
'File uploading failed: server returned '
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment