I've been trying to generate a public downloadable URL for OneDrive
for Business and SharePoint DriveItem object using /createLink api.
curl \
-X POST \
-d '{"type":"view","scope":"anonymous"}' \
-H 'Authorization: bearer xxx_Access_Token_xxx' \
-H 'Content-Type: application/json' \
"https://graph.microsoft.com/v1.0/drive/items/<item-id>/createLink"
Above call returns JSON result with body.link.webUrl (https://my.sharepoint.com/:u:/g/XXXXrKmGKlXXXXXXXXXXsq0Bh3x4TTXXXXXXXXXXXXXXXXX) being the sharable URL. However, this link doesn't contain the reference to file directly.
As per this comment, appending download=1 as query string parameter to generated shared URL will allow the user to open the original file directly. But I could not find any documentation supporting this behavior.
Is it possible to
Download the file directly.
To use public URL as src attribute of img tag.
You may follow official document of OneDrive
You will have to put below line of code in success field of IProgressCallback. Here ItemId is "id of uploaded item".
String itemId = result.id;
TestBase testBase = new TestBase(xdata.getinstance().getSetting(config.onedriveaccesstoken));
AsyncTask<Void, Void, Void> downloadfileonedrive = new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(final Void... params) {
com.microsoft.graph.models.extensions.Permission response = testBase.graphClient
.me()
.drive()
.items(itemId)
.createLink("edit", "anonymous")
.buildRequest().post();
Log.e("Sharable link : ", ""+response);
try {
String sharabalelink = new JSONObject(response.getRawObject().getAsJsonObject("link").toString()).getString("webUrl");
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onCancelled() {
super.onCancelled();
}};
downloadfileonedrive.execute();
Related
I made a small spring boot application (2.2.5.RELEASE)
and I want to have swagger and I use springdoc-openapi-ui version 1.6.8.
I have in my application.properties my setting "swagger-ui.hostname" which is an empty string by default.
Other settings I have for springdoc are
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.use-root-path=false
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.enabled=true
springdoc.api-docs.enabled=true
I can run locally the application and execute the GET endpoint test.
I can see
http://localhost:8089/swagger-ui.html
( "swagger-ui.hostname" is an empty string )
I have one problem when I do deploy on tomcat server and I use
"-Dswagger-ui.hostname=company.com-live".
The problem is swagger or openapi generates url wrong for curl in the page swagger-ui.html when I execute one endpoint test (get).
I can see in the page of swagger
https://company.com-live/swagger-ui.html
curl -X 'GET' \
'https://company.com-live/api-docs/company.com-live/test' \
-H 'accept: */*'
The app was started with
"-Dswagger-ui.hostname=https://company.com-live"
( "company.com-live" is duplicated and "/api-docs" is added )
I expected this url
https://company.com-live/test
These works
https://company.com-live/internal/mon/info
https://company.com-live/ping
How to configure correct the swagger OpenAPI to obtain this url ?
https://company.com-live/test
Java code for configuration is
#Configuration
#Slf4j
public class SwaggerConfig {
#Value("${swagger-ui.hostname:}")
private String hostname;
#Bean
public OpenAPI springShopOpenAPI() {
List<Server> serversList = new ArrayList<>();
System.out.println(message);
log.info(message);
if (StringUtils.isNoneBlank(hostname)) {
serversList.add(new Server().url(hostname));
}
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("basicScheme",
new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("basic")))
.info(new Info()
.title("MyTools")
.description("MyTools")
.version("1.0.0")
.contact(new Contact()
.email("it-operations#company.com")
.name("Company support"))
.license(new License()
.name("Company")
.url("https://company.com")))
.servers(serversList);
}
#Bean
public GroupedOpenApi addressesApi() {
return GroupedOpenApi.builder()
.group("Test group")
.pathsToMatch("/test/**")
.build();
}
#Bean
public GroupedOpenApi pingApi() {
return GroupedOpenApi.builder()
.group("Ping")
.pathsToMatch("/ping/**")
.build();
}
}
Here I am again trying to use the Design Automation SDK and I get this error when I try to retrieve bundle aliases, versions or other information that require the id.
I am testing that using one of the existing appbundles available...
public static async Task<dynamic> GetAppBundleVersionsAsync(ForgeService service, Token token, string id)
{
try
{
if (token.ExpiresAt < DateTime.Now)
token = Get2LeggedToken();
AppBundlesApi appBundlesApi = new AppBundlesApi(service);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("Authorization", "Bearer " + token.AccessToken);
headers.Add("content-type", "application/json");
var aliases = await appBundlesApi.GetAppBundleVersionsAsync(id, null, null, headers);
return aliases;
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error : {0}", ex.Message));
return null;
}
}
Almost thinking to go to my previous RestSharp implementation :)
There are 2 kinds of IDs:
Fully qualified (string in format owner.name+alias)
Unqualified (just name)
You are trying to list versions of your own AppBundle, so you need to use Unqualified. It seems your ID is fully qualified form.
For more info look at API documentation description of endpoint id parameter you are using https://forge.autodesk.com/en/docs/design-automation/v3/reference/http/design-automation-appbundles-id-versions-GET/#uri-parameters
Hi I am writing custom plugin for elastic search,
but I unable to get the parameter from the post request.
#Inject
public HelloRestHandler(Settings settings, RestController restController, Client esClient) {
super(settings, restController, esClient);
restController.registerHandler(RestRequest.Method.GET, "/_hello", this);
restController.registerHandler(RestRequest.Method.POST, "/_hello", this);
restController.registerHandler(RestRequest.Method.PUT, "/_hello", this);
}
#Override
public void handleRequest(final RestRequest request, final RestChannel channel, Client esClient) {
ObjectMapper mapper = new ObjectMapper();
String json;
try{json= mapper.writeValueAsString(request.params());}catch (Exception exp){ json ="not found";}
channel.sendResponse(new BytesRestResponse(OK,json));}
The curl:
curl -XPOST "http://localhost:9200/_hello/" -d '{"first":"1"}'
response :
"{}" (empty JSON)
Please help me out to fix my issue. Thanks.
request.params() returns the HTTP parameters passed in the query string. In your case, there are none. Try with request.content() instead.
String json;
try{
json = mapper.writeValueAsString(request.content());
} catch (Exception exp){
json ="not found";
}
channel.sendResponse(new BytesRestResponse(OK,json));
I'm trying to accept application/x-www-form-urlencoded data on my webApi endpoint. When I send a request with PostMan that has this Content-Type header explicitly set, I get an error:
The request contains an entity body but no Content-Type header
My Controller:
[HttpPost]
[Route("api/sms")]
[AllowAnonymous]
public HttpResponseMessage Subscribe([FromBody]string Body) { // ideally would have access to both properties, but starting with one for now
try {
var messages = _messageService.SendMessage("flatout2050#gmail.com", Body);
return Request.CreateResponse(HttpStatusCode.OK, messages);
} catch (Exception e) {
return Request.CreateResponse(HttpStatusCode.InternalServerError, e);
}
}
The POSTMAN cap:
What am I doing wrong?
If you look at the request message, you can see that Content-Type header is being sent like this.
Content-Type: application/x-www-form-urlencoded, application/x-www-form-urlencoded
So, you are adding the Content-Type header manually and POSTMAN is adding that as well, since you have selected the x-www-form-urlencoded tab.
If you remove the header you have added, it should work. I mean you will not get an error but then binding will not work because of the simple type parameter [FromBody]string Body. You will need to have the action method like this.
public HttpResponseMessage Subscribe(MyClass param) { // Access param.Body here }
public class MyClass
{
public string Body { get; set; }
}
Instead, if you insist on binding to string Body, do not choose the x-www-form-urlencoded tab. Instead choose the raw tab and send the body of =Test. Of course, in this case, you have to manually add the `Content-Type: application/x-www-form-urlencoded' header. Then, the value in the body (Test) will be correctly bound to the parameter.
I have controller:
class MyController extends AbstractRestfulController{
protected $myTable;
public function getList(){
$results = $this->getMyTable()->fetchAll();
$data = array();
foreach($results as $result) {
$data[] = $result;
}
return new JsonModel(array(
'data' => $data
));
}
[...]
and I check:
curl -i -H "Accept: application/json" http://localhost/myapp/restroute -X GET
and it's fine. But I want to send to this method extra data, for example:
curl -i -H "Accept: application/json" http://localhost/myapp/restroute -X GET -d "name=john"
How to read this data in getList() method?
I could use create($data) method but somehow it does not fit me (create method is for creation, etc). I want, for example get list of some type of objects limited by variable in $_GET.
Within AbstractRestfulController, there's a helper method called processBodyContent which is ideal for what you're trying to do:
public function getList()
{
$content = $this->processBodyContent($this->getRequest());
$name = array_key_exists('name', $content) ? $content['name'] : '';
// ...
}
As you're using GET thought, you should consider doing:
curl -i -H "Accept: application/json" http://localhost/myapp/restroute?name=john -X GET
You can then retrieve within getList() like this:
public function getList()
{
$name = $this->params()->fromQuery('name');
// ...
}