Hi Aman,

Your PHP snippet doesn't have all that much information.

https://wiki.duraspace.org/display/DSDOC5x/REST+API#RESTAPI-Items
>From the documentation, to upload an item is:

   - POST /items/{item id}/bitstreams - Add bitstream to item. You must
   post a Bitstream



>From the readme: https://demo.dspace.org/rest

   - POST /items/{item id}/bitstreams - Add a bitstream to the specified
   item.


ENDPOINT: https://demo.dspace.org/rest/items/22/bitstreams?name=beach.jpg


For each of your actions that your trying to make your code do, until there
is a DSpace SDK for each language, the best process to get your integration
working, would be to see how one of the other example applications
accomplishes this (I should still polish those examples up), also, ensure
that you can accomplish the goal (upload a bitstream) from a simple tool,
such as curl, or my favorite Advanced Rest Client chrome extension. Here's
how to upload a bitstream using the advanced rest client:

Step 1, login
URL: https://demo.dspace.org/rest/login
METHOD: POST

Headers raw:
Accept: application/json

Payload raw:
{
  "email" : "dspacedemo+ad...@gmail.com",
  "password" : "dspace"
}

Content-type: application/json


The RESPONSE is HTTP 200 OK with a body of:
e6d7c978-fc36-4ead-a108-205ca2f4f592
That long string is that rest-dspace-token.


Step 2, upload file
URL: https://demo.dspace.org/rest/items/22/bitstreams
It is better to send the filename along with your request, so a better
endpoint URL should add the filename, so:
URL: https://demo.dspace.org/rest/items/22/bitstreams?name=beach.jpg


METHOD: POST

Headers raw:
Accept: application/json
rest-dspace-token: e6d7c978-fc36-4ead-a108-205ca2f4f592

Payload Files
(Use dialog box to chose the file to upload, there is no other json/xml in
your request)

And send that.

You should get HTTP status 200 ok, and the response is a bitstream object
in json (because your accept header).




So, see if that helps to guide you, in updating your PHP. Maybe its helpful
to do this in plain-old curl.


________________
Peter Dietz
Longsight
www.longsight.com
pe...@longsight.com
p: 740-599-5005 x809

On Wed, Jun 10, 2015 at 6:02 AM, Aman Singh <singh26.a...@gmail.com> wrote:

> Hi Peter,
>
> Need your help again. This time I am trying to upload a file using
> curl_setopt in php5.5 and @ is deprecated as  prefix.
> So , can you help me writing request body again. I have tried using
> CURLFile enabling safe upload but every time  a txt file with all the data
> is getting uploaded.
>
> This is the var_dump of postfields
>
> array(4) { ["name"]=> string(5) "test1" ["format"]=> string(4) "text"
> ["sizeBytes"]=> string(12) "I don't know" ["test file "]=>
> object(CURLFile)#1 (3) { ["name"]=> string(8) "test.txt" ["mime"]=>
> string(3) "txt" ["postname"]=> string(4) "test" } }
>
> and
> This is what I am getting by retrieve link
>
> {"name":"test1","format":"text","sizeBytes":"I don't know","test file
> ":{"name":"test.txt","mime":"txt","postname":"test"}}
>
>
> here is the relevant part of my code
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL,$params['url']);
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_HTTPHEADER, $params['header']);
> var_dump(array_key_exists("filename",$params));
>
> if(!array_key_exists("filename",$params))
> curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($params['rqst']));
> else {
>     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1);
>     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
>     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
>     $cfile =
> curl_file_create($params['filename'],$params['mimeType'],'test');
>     $params['rqst']['test file ']= $cfile;
>     var_dump( $params['rqst']);
>     curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($params['rqst']));
> }
>
>
>
> Thanks in advance
>
>
> On Sat, Jun 6, 2015 at 5:48 PM, Aman Singh <singh26.a...@gmail.com> wrote:
>
>> Thanks Peter Dietz , finally it's working now.
>>
>> On Fri, Jun 5, 2015 at 8:29 PM, Peter Dietz <pe...@longsight.com> wrote:
>>
>>> Hi Aman,
>>>
>>> You can test this example application to see the flow:
>>> https://github.com/DSpace-Labs/dspace-rest-requests
>>>
>>> The json you pass in, should look like:
>>> {
>>>   "email" : "EMAIL",
>>>   "password" : "PASSWORD"
>>> }
>>>
>>> So, debug what your passing in. And try it with something like chrome
>>> extension Advanced Rest Client.
>>>
>>> ________________
>>> Peter Dietz
>>> Longsight
>>> www.longsight.com
>>> pe...@longsight.com
>>> p: 740-599-5005 x809
>>>
>>> On Fri, Jun 5, 2015 at 10:19 AM, Aman Singh <singh26.a...@gmail.com>
>>> wrote:
>>>
>>>> hi mark,
>>>> Yeah thats just a placeholder for the mail, I'm passing the correct
>>>> email and password while testing.
>>>>
>>>> anything else that could be the problem.
>>>>
>>>> Thanks
>>>>
>>>> On Fri, Jun 5, 2015 at 7:34 PM, Mark H. Wood <mw...@iupui.edu> wrote:
>>>>
>>>>> On Fri, Jun 05, 2015 at 07:28:16PM +0530, Aman Singh wrote:
>>>>> > hi all,
>>>>> >
>>>>> > I am trying login in Dspace remote server and getting error 500 and
>>>>> log
>>>>> > file shown below .
>>>>> > HTTP Status 500 - org.codehaus.jackson.JsonParseException: Unexpected
>>>>> > character ('e' (code 101)): expected a valid value (number, String,
>>>>> array,
>>>>> > object, 'true', 'false' or 'null')
>>>>> >
>>>>> > *type* Exception report
>>>>> >
>>>>> > *message* *org.codehaus.jackson.JsonParseException: Unexpected
>>>>> character
>>>>> > ('e' (code 101)): expected a valid value (number, String, array,
>>>>> object,
>>>>> > 'true', 'false' or 'null')*
>>>>> >
>>>>> > *description* *The server encountered an internal error that
>>>>> prevented it
>>>>> > from fulfilling this request.*
>>>>> >
>>>>> > *exception*
>>>>> >
>>>>> > javax.servlet.ServletException:
>>>>> > org.codehaus.jackson.JsonParseException: Unexpected character ('e'
>>>>> > (code 101)): expected a valid value (number, String, array, object,
>>>>> > 'true', 'false' or 'null')
>>>>> >  at [Source: org.apache.catalina.connector.CoyoteInputStream@3fe07138
>>>>> ;
>>>>> > line: 1, column: 2]
>>>>> >
>>>>>  
>>>>> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
>>>>> >       javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>>>>> >
>>>>>  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>>>>> >
>>>>> > *root cause*
>>>>> >
>>>>> > org.codehaus.jackson.JsonParseException: Unexpected character ('e'
>>>>> > (code 101)): expected a valid value (number, String, array, object,
>>>>> > 'true', 'false' or 'null')
>>>>> >  at [Source: org.apache.catalina.connector.CoyoteInputStream@3fe07138
>>>>> ;
>>>>> > line: 1, column: 2]
>>>>> >
>>>>>  org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432)
>>>>> >
>>>>>  
>>>>> org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
>>>>> >
>>>>>  
>>>>> org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)
>>>>> >
>>>>>  
>>>>> org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:2084)
>>>>> >
>>>>>  
>>>>> org.codehaus.jackson.impl.Utf8StreamParser._nextTokenNotInObject(Utf8StreamParser.java:600)
>>>>> >
>>>>>  
>>>>> org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:486)
>>>>> >
>>>>>  
>>>>> org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2761)
>>>>> >
>>>>>  org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2682)
>>>>> >
>>>>>  org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
>>>>> >
>>>>>  
>>>>> org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:488)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
>>>>> >
>>>>>  
>>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
>>>>> >       javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>>>>> >
>>>>>  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>>>>> >
>>>>> > *note* *The full stack trace of the root cause is available in the
>>>>> Apache
>>>>> > Tomcat/8.0.21 logs.*
>>>>> >
>>>>> >
>>>>> > Php fcode which I am using for this purpose is below ...
>>>>> >
>>>>> > <?php
>>>>> >
>>>>> >
>>>>> > $header=['Content-Type:application/json','Accept:JSON'];
>>>>> > $ch = curl_init();
>>>>> >
>>>>> > curl_setopt($ch, CURLOPT_URL,"http://localhost:8080/rest/login/";);
>>>>> > curl_setopt($ch, CURLOPT_POST, 1);
>>>>> > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // receive server
>>>>> response ...
>>>>> > curl_setopt($ch, CURLOPT_TIMEOUT, 4);
>>>>> > curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
>>>>> > //curl_setopt($ch, CURLOPT_USERPWD,
>>>>> $your_username.':'.$your_password);
>>>>> > curl_setopt($ch,
>>>>> >
>>>>> CURLOPT_POSTFIELDS,http_build_query(array('email'=>'emailaddress','password'=>'passs')));
>>>>>
>>>>> Should the above line not be:
>>>>>
>>>>> >
>>>>> CURLOPT_POSTFIELDS,http_build_query(array('email'=>$your_username,'password'=>$your_password)));
>>>>>
>>>>> >
>>>>> >
>>>>> >
>>>>> > $server_output = curl_exec ($ch);
>>>>> > echo $server_output;
>>>>> > // var_dump($server_output
>>>>> > if (curl_errno($ch)) {
>>>>> >  print curl_error($ch);
>>>>> > } else {
>>>>> >
>>>>> > }
>>>>> > curl_close ($ch);
>>>>> >
>>>>> >
>>>>> > // further processing ....
>>>>> > ?>
>>>>> >
>>>>> >
>>>>> > If anyone can point out the error in my code and how to debug it ?
>>>>> >
>>>>> > Thanks in advance
>>>>>
>>>>> >
>>>>> ------------------------------------------------------------------------------
>>>>>
>>>>> > _______________________________________________
>>>>> > DSpace-tech mailing list
>>>>> > DSpace-tech@lists.sourceforge.net
>>>>> > https://lists.sourceforge.net/lists/listinfo/dspace-tech
>>>>> > List Etiquette:
>>>>> https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette
>>>>>
>>>>>
>>>>> --
>>>>> Mark H. Wood
>>>>> Lead Technology Analyst
>>>>>
>>>>> University Library
>>>>> Indiana University - Purdue University Indianapolis
>>>>> 755 W. Michigan Street
>>>>> Indianapolis, IN 46202
>>>>> 317-274-0749
>>>>> www.ulib.iupui.edu
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>>
>>>>> _______________________________________________
>>>>> DSpace-tech mailing list
>>>>> DSpace-tech@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/dspace-tech
>>>>> List Etiquette:
>>>>> https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette
>>>>>
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>>
>>>> _______________________________________________
>>>> DSpace-tech mailing list
>>>> DSpace-tech@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/dspace-tech
>>>> List Etiquette:
>>>> https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette
>>>>
>>>
>>>
>>
>
------------------------------------------------------------------------------
_______________________________________________
DSpace-tech mailing list
DSpace-tech@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dspace-tech
List Etiquette: https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette

Reply via email to