I am building a project using Corda.
I use RESTful api to invoke flows to create and update a state. But how can I upload a pdf file to node using attachment function in Corda?
Any help is appreiciated
If you are using spring servers then use below logic :
create an api that uses the multipart request and include the below
code in it.
msg = proxy.uploadAttachment(new ByteArrayInputStream(getZippedBytes(file))).toString();//msg returns the unique hashid for this attachment.
//getZippedBytes(file)) returns the byte[]
If you're using the built-in webserver, you need to encode the attachment as multipart/form-data and post it to NODE_WEBSERVER_ADDRESS/upload/attachment.
See an example here: https://github.com/corda/samples/blob/release-V3/blacklist/src/main/resources/blacklistWeb/index.html.
Related
I add a new api in the file below:
carbon-apimgt\components\apimgt\org.wso2.carbon.apimgt.rest.api.publisher.v1\src\main\resources\publisher-api.yaml
Maven build success and generate some new files which are definded in the publisher-api.yaml.
I use postman to invoke this api but get a null response , why? How can i reuqest it?
When you update the publisher-api.yaml with a new resource, you have to build two components.
carbon-apimgt/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1
carbon-apimgt/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common
This will generate the required DTOs and interfaces for the implementation of the new resource.
Then you have to implement the logic behind the new resource. carbon-apimgt/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl will now have a new java file and you can add the logic.
I use api-platform for the first time and I am looking for the best way to upload files.
My situation :
An entity "Post" with a OneToMany relation "Media" (SonataMedia) on server side, I'm working on the create view (Angular + Restangular).
All fields (except file type fields) are functional (persist OK). Now, for the file type fields, what do I have to do?
Asynchronous upload? in this case how to link files upload with my entity (which is not persisted yet)
upload files on form entity submit?
In every case, what it needs to send to server? How Api-platform manages it?
There is no builtin file upload support as time of writing in API Platform. You need to write your own code to handle uploads.
However, some work is some work being done to natively add this feature and you can already use it.
Basically, the idea is:
Encode the file to upload as data: URI client-side (using JavaScript)
Send this data URI (basically a base64 string) as a typical string entity property using Restangular (or any other HTTP client)
Decode the data: URI server-side to a regular file using the Symfony Serializer
Store this regular file on the server: it's up to you to store it on the filesystem or in more advanced backends such as Mongo GridFS or Amazon S3
Client-side
To get a data: URI client-side from a selected file, you can rely on the readAsDataURL of the FileReader JavaScript API: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL.
Send the resulting string as usual using Restangular.
Server-side
The API Platform normalization system is built on top of the Symfony Serializer. I've contributed a data: URI normalizer and denormalizer in Symfony: https://github.com/symfony/symfony/pull/16164
It is not merged yet but you can copy it in your own project during the meantime.
Register the normalizer:
services:
data_uri_normalizer:
class: 'AppBundle\Serializer\DataUriNormalizer'
tags:
- { name: serializer.normalizer }
Then create (and register) a new normalizer decorating the ItemNormalizer of API Platform to transform your property containing the file encoded as a data: URI to a standard \SplFileObject using the DataUriNormalizer::denormalize() method.
In a future version of API Platform (planned for the v2.1 with Symfony 3.1) all this logic will be automatically available and registered.
I need to implement a web script that generates a returns the ticket for the current user. This web script is addressed by the URI I use to setup a URLConncetion. The ticket should be contained in the response body, which I need to evaluate in my JSP (or Java code) to extract the ticket. How can be done by a simple JavaScript / FreeMarker web script, using the JavaScript session root scope object to retrieve the ticket, i.e. session.getTicket() ?
Can any one pls write the steps to do?
ticket.get.html.ftl (or json or whatever you want):
${session.ticket}
JSON data :
{"user":[{"address":"HYD0","id":"0","name":"XXXX0"},
{"address":"HYD1","id":"1","name":"XXXXX1"},
{"address":"HYD2","id":"2","name":"XXXXXX2"}]}
so how should i call restful webservice in webscript and display the data on free marker template and dashlet?
the rest web service placed some where, now i want to invoke it from web script.
When working in Share, Surf provides a way to access other systems to fetch data. This is done via the remote object, and if you look at many of the Share WebScripts you'll see things like:
var connector = remote.connect("alfresco");
var result = connector.get("/api/foo/bar?thing=stuff");
if (result.status == status.STATUS_OK)
{
return eval('(' + result.response + ')');
}
The remote object in JavaScript is provided by the ScriptRemote object. If you browse the source for that, you'll see how it all works and fits together
The most common use is with the alfresco endpoint, which connects back to the Alfresco Repository tier so you can call repo webscripts. One option is for you to define your own endpoint to Share via the spring config, then you can access that with a friendly name. The other is to do what the RSS Feed Utils does and request the http endpoint, then give a full URL.
Either way, you'll want to fetch the remote URL, check you got a valid response, eval it to get the data, and store that in your model. That data will then be available in the FTL to render as you want.
In my controller, based on user post, i want to make a call to an external provider site to get process some data and get results.
example: say i want to invoke google map api at the following url
http://maps.googleapis.com/maps/api/directions/output?
This call returns an xml object with data, which I would like to use.
Only using google as an example here, but concept is the same.
How would I make the call in spring mvc controller or in the business[service] layer?
I came across jersey client which allows me to go against RESTful service.
This is the link I used:
Jersey Sample Client
Jersey Sample Client from oracle
I think you can open a http request inside a controller /Service ( Service sounds better )
I remember doing in other web framewoks with Apache http client (http://hc.apache.org/ ) but I would try google-api-client or google-api-client-servlet .
I m trying right now .