I am trying to figure out a workaround for refreshing dataset with Custom functions over Power BI service. My query looks like the following:
Data source for _op_kiekis
let
Source = Loginai_File,
#"Invoked Custom Function" = Table.AddColumn(Source, "Q_Sybase_2_Op_Kiekis", each Q_Sybase_2_Op_Kiekis([Source], [IP], [PORT], [DB_name]))
in
#"Invoked Custom Function"
Data source for _eil_sk
let
Source = Loginai_File,
#"Invoked Custom Function" = Table.AddColumn(Source, "Q_Sybase_1_Eil_Sk_2", each Q_Sybase_1_Eil_Sk_2([Source], [IP], [PORT], [DB_name]))
in
#"Invoked Custom Function"
Loginai_File
let
Source = Excel.Workbook(File.Contents(PathToLoginai & Loginai_File_Name), null, true),
dbs = Source{[Name="Sheet1"]}[Data],
in
dbs
Q_Sybase_2_Op_Kiekis
(Name, strSource, Ip , Port, dBase ) =>
let
Source = Sybase.Database(Ip & ":" & Number.ToText(Port), dBase, [Query="select [_].[Count] from [DBA].[dbs] [_] where [_].[DID_DAT] >= '" & sFilterDate & "' order by [DID_DAT]"])
in
Source
Q_Sybase_1_Eil_Sk_2
(Name, strSource, Ip , Port, dBase ) =>
let
Source = Sybase.Database(Ip & ":" & Number.ToText(Port), dBase, [Query="select [_].[Count] from [DBA].[dbs2] [_] where [_].[DID_DAT] >= '" & sFilterDate & "' order by [DID_DAT]"])
in
Source
This works fine on Power BI desktop. However, I am getting following error on Power BI service:
You need a SQL Server wrapper: PowerBI doesnt play nicely with Sybase but you have a work around that will fully support refreshes where Sybase is actually the back-end datastore:
Setup SQL Server and add it to your Datagateway
On your SQL Server add a linked Server Connection to your Sybase Servers from your new SQL Server. https://www.sqlservercentral.com/articles/connect-to-sybase-with-a-linked-server
In PowerBI connect as a SQL Server data source and access the linked servers you setup on your SQL Server to get to the Sybase data.
I have a hosted http service that accepts a trend data and returns some output. This service is accessed in siddhi query language as follows:
#sink(type='http-request', sink.id='trends',
publisher.url='${SERVICE_URL}', #map(type='json', #payload(""" {"trend":{{trendArray}} } """) ) )
define stream Request(item string, trendArray string);
#source(type='http-response' , sink.id='trends', http.status.code='200',
#map(type='json', #attributes(stock = '<HOW_TO_GET_THIS_VALUE>', output = "<HOW_TO_GET_THIS_VALUE>")
) )
define stream Response(item string, output string);
The http request(and response) payload doesn't include item name.
when the response comes we would like to assign item name against which we scored the output - marked as HOW_TO_GET_THIS_VALUE above.
How to accomplish this in siddhi query ?
How to treat the response data of as-is as pass to the field ?
I did not see a description of this scenario in siddhi. If not supported, it will good to know details of a custom extension (based out of http extension) for this scenario. Solution to add a proxy layer for http call is less desired.
After some experiments , HOW_TO_GET_THIS_VALUE = 'trp:item'. The http sink should also have this field even though its not used in payload.
I am using Spring MVC and this is my method:
/**
* Upload single file using Spring Controller.
*/
#RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public #ResponseBody ResponseEntity<GenericResponseVO<? extends IServiceVO>> uploadFileHandler(
#RequestParam("name") String name,
#RequestParam("file") MultipartFile file,
HttpServletRequest request,
HttpServletResponse response) {
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
// Creating the directory to store file
String rootPath = System.getProperty("catalina.home");
File dir = new File(rootPath + File.separator + "tmpFiles");
if (!dir.exists()) {
dir.mkdirs();
}
// Create the file on server
File serverFile = new File(dir.getAbsolutePath() + File.separator + name);
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
stream.write(bytes);
stream.close();
System.out.println("Server File Location=" + serverFile.getAbsolutePath());
return null;
} catch (Exception e) {
return null;
}
}
}
I need to pass the session id in postman and also the file. How can I do that?
In postman, set method type to POST.
Then select
Body -> form-data -> Enter your parameter name (file according to your code)
On the right side of the Key field, while hovering your mouse over it, there is a dropdown menu to select between Text/File. Select File, then a "Select Files" button will appear in the Value field.
For rest of "text" based parameters, you can post it like normally you do with postman. Just enter parameter name and select "text" from that right side dropdown menu and enter any value for it, hit send button. Your controller method should get called.
The Missing Visual Guide
You must first find the nearly-invisible pale-grey-on-white dropdown for File which is the magic key that unlocks the Choose Files button.
After you choose POST, then choose Body->form-data, then find the File dropdown, and then choose 'File', only then will the 'Choose Files' button magically appear:
Maybe you could do it this way:
Like this :
Body -> form-data -> select file
You must write "file" instead of "name"
Also you can send JSON data from Body -> raw field. (Just paste JSON string)
I got confused after seeing all of the answers, I couldn't find any proper screenshot to bring the Content Type column. After some time, I found it by my own. Hope this will help somebody like me.
Here is the steps:
click on red marked area of postman.
Now check the green marked option (Content Type).
Now change the search content type, in the yellow marked area.
In my case:
invoice_id_ls (key) contains the json data.
documents contains the file data.
placed_amount contains normal text string.
Select [Content Type] from [SHOW COLUMNS] then set content-type of "application/json" to the parameter of json text.
Don't give any headers.
Put your json data inside a .json file.
Select your both files one is your .txt file and other is .json file
for your request param keys.
If somebody wants to send json data in form-data format just need to declare the variables like this
Postman:
As you see, the description parameter will be in basic json format, result of that:
{ description: { spanish: 'hola', english: 'hello' } }
Kindly follow steps from top to bottom as shown in below image.
At third step you will find dropdown of type selection as shown in below image
Body > binary > Select File
If you need like
Upload file in multipart using form data and send json data(Dto object) in same POST Request
Get yor JSON object as String in Controller and make it Deserialize by adding this line
ContactDto contactDto = new ObjectMapper().readValue(yourJSONString, ContactDto.class);
If somebody needed:
body -> form-data
Add field name as array
Use below code in spring rest side :
#PostMapping(value = Constant.API_INITIAL + "/uploadFile")
public UploadFileResponse uploadFile(#RequestParam("file") MultipartFile file,String jsonFileVo) {
FileUploadVo fileUploadVo = null;
try {
fileUploadVo = new ObjectMapper().readValue(jsonFileVo, FileUploadVo.class);
} catch (Exception e) {
e.printStackTrace();
}
If you want to make a PUT request, just do everything as a POST request but add _method => PUT to your form-data parameters.
The way to send mulitpart data which containts a file with the json data is the following, we need to set the content-type of the respective json key fields to 'application/json' in the postman body tab like the following:
You can send both Image and optional/mandatory parameters.
In postman, there is Params tab.
I needed to pass both: a file and an integer. I did it this way:
needed to pass a file to upload:
did it as per Sumit's answer.
Request type : POST
Body -> form-data
under the heading KEY, entered the name of the variable ('file' in my backend code).
in the backend:
file = request.files['file']
Next to 'file', there's a drop-down box which allows you to choose between 'File' or 'Text'. Chose 'File' and under the heading VALUE, 'Select files' appeared. Clicked on this which opened a window to select the file.
2.
needed to pass an integer:
went to:
Params
entered variable name (e.g.: id) under KEY and its value (e.g.: 1) under VALUE
in the backend:
id = request.args.get('id')
Worked!
For each form data key you can set Content-Type, there is a postman button on the right to add the Content-Type column, and you don't have to parse a json from a string inside your Controller.
first, set post in method and fill link API
Then select Body -> form-data -> Enter your parameter name (file according to your code)
If you are using cookies to keep session, you can use interceptor to share cookies from browser to postman.
Also to upload a file you can use form-data tab under body tab on postman, In which you can provide data in key-value format and for each key you can select the type of value text/file. when you select file type option appeared to upload the file.
If you want the Id and File in one object you can add your request object to a method as standard and then within Postman set the Body to form-data and prefix your keys with your request object name. e.g. request.SessionId and request.File.
The steps of uploading a file through postman along with passing some input data is very well discussed in below blog along with the screenshot. In this blog, the api code is written in node js. You can go through it once to have more clarity.
https://jksnu.blogspot.com/2021/09/how-to-create-post-request-with.html
At Back-end part
Rest service in Controller will have mixed #RequestPart and MultipartFile to serve such Multipart + JSON request.
#RequestMapping(value = "/executesampleservice", method = RequestMethod.POST,
consumes = {"multipart/form-data"})
#ResponseBody
public boolean yourEndpointMethod(
#RequestPart("properties") #Valid ConnectionProperties properties,
#RequestPart("file") #Valid #NotNull #NotBlank MultipartFile file) {
return projectService.executeSampleService(properties, file);
}
At front-end :
formData = new FormData();
formData.append("file", document.forms[formName].file.files[0]);
formData.append('properties', new Blob([JSON.stringify({
"name": "root",
"password": "root"
})], {
type: "application/json"
}));
See in the image (POSTMAN request):
Click to view Postman request in form data for both file and json
To send image along with json data in postman you just have to follow the below steps .
Make your method to post in postman
go to the body section and click on form-data
provide your field name select file from the dropdown list as shown below
you can also provide your other fields .
now just write your image storing code in your controller as shown below .
postman :
my controller :
public function sendImage(Request $request)
{
$image=new ImgUpload;
if($request->hasfile('image'))
{
$file=$request->file('image');
$extension=$file->getClientOriginalExtension();
$filename=time().'.'.$extension;
$file->move('public/upload/userimg/',$filename);
$image->image=$filename;
}
else
{
return $request;
$image->image='';
}
$image->save();
return response()->json(['response'=>['code'=>'200','message'=>'image uploaded successfull']]);
}
That's it hope it will help you
I am trying to load/save a document from S3 using AWS API (S3 proxy) and angular js. code as below
response type is marked as array buffer and is then converted as blob with UTF8 and type as "application/msword" (verified content type from S3 API)
download is successful however the file isn't showing up and an error "select encoding that makes your document readable"
tried with pdf document with type application/pdf, pdf opens but shows no data.
Any clue whats wrong here
$scope.URL = "https://jkq1yea3e5.execute-api.ap-south-1.amazonaws.com/Prod" + "/s3resources/"+"testfolder/"+ $scope.filename;
$http.get($scope.URL, {responseType: "arraybuffer"}).
success(function(data) {
$scope.info = "Read '" + $scope.URL + "' with " + data.byteLength
+ " bytes in a variable of type '" + typeof(data) + "'";
blob= new Blob([data], {type: $scope.type+";charset=utf-8"});
var url = window.URL.createObjectURL(blob);
var linkElement = document.createElement('a');
linkElement.setAttribute('href', url);
linkElement.setAttribute("download", $scope.filename);
linkElement.click();
FileSaver.saveAs(blob, $scope.filename,true);
After struggling for hours, here is what worked for me.
added application/msword in binary types for the AWS API
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-workflow.html
I have an application that uploads bulk (master) data from users. Now instead of creating forms i figured that i could download the existing data into excel and the user simply changes what they need to in Excel, and click on say 'save' or some buttom provided on theexcel worksheet, which in turn invokes a web service to load this data into the app. (we already have a web service api for this). I am assuming that when i download the excel file (from the server) to the user, the macros that are in the excel file are also now available to the user.
Any thoughts on the approach and if this sounds ok, any suggestions on how i can modify the excel file so that when the user clicks 'save' it gets uploaded (rather that get saved on the users system). Also not sure how to invoke a WS from within Excel to do this.
thx in advance,
-anish
While some of the details you may have to investigate yourself, I've created the following library for interacting with web services that may help:
https://github.com/timhall/Excel-REST
Here's a quick example:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Api As New RestClient
Api.BaseUrl = "http://.../yourapi/"
Dim Data As New Collection
' Add data from sheet...
' Create update request to api
Dim Request As New RestRequest
Request.Resource = "resource/{id}"
Request.AddUrlSegment "id", "123"
Request.Body Data
Request.Method = httpPUT
' Execute the update
Dim Response As RestResponse
Set Response = Api.Execute(Request)
' Check on what happened
If Response.StatusCode < 400 Then
' Success!
Else
' Uh oh, check on the error
MsgBox Response.Content
End If
End Sub