I am using ng-file-upload AngularJs API to upload multiple files to server.But this is the traditional way to do it.But my requirement is that i dont need to store files in a server as it is.I have a REST end point that responsible for store user input data to DB.Along with the REST request i pass the file Array object with other forms values.When data comes to REST end point it access each attributes and store data.When it tried to read File Array obj i can not read the file content for each file.
Sample File Upload Code
jsfiddle
Note that i just want to pass only $scope.files along with the REST request.Please let me know how can i read file content values from server side reading file Array in Java.If you guys know any better way to do this please share your ideas.
REST Service Code Snippet
#POST
#Path("/manual")
#Produces(MediaType.APPLICATION_JSON)
public boolean insertResults(testVO testResult) {
for(Object o:testVO.getFiles()){
LinkedHashMap<String, String> l=(LinkedHashMap<String, String>) o;
System.out.println(l.get("result"));
}
}
Note: testVO.getFiles() type is Object[] array.
In my preceding code i convert object into LinkedHashMap and access the necessary fields like size,type,etc.But my requirement is that how can i get the content belong to that file.
Related
I am creating a Spring Cloud Function that I want to give two inputs, an id and a Multipart file (CSV file) but I am having trouble.
If I choose to send a post with a multipart file the function won't recognise this and gives an error like Failed to determine input for function call with parameters:
With the Postman request being this:
#Bean
public Function<MultipartFile, String> uploadWatchlist() {
return body -> {
try {
return service.convert(body);
}
}
}
I have tried using something more akin to Spring MVC like a request entity object but no luck.
The backup I have (other than Python haha) will be using the binary data post so it will just be a string that has the contents of the file which does work, but requires me to append the id inside to each row of the csv which is a bit messy.
There are other solutions but trying to get this working as Java lambdas are what we want to try and use as first choice.
The infrastructure will be to fix up a manual file upload/verification process that is tedious at the moment and looks like: postman -> load balancer -> lambda -> ecs
The postman/load balancer part will be replaced in future. Ideally have the lambda sorted in Java taking in a file and id.
Thanks for any help :)
I know how to retrieve a file with a specified name like this:
HttpGet httpGet = new HttpGet(siteUrl +
"_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/Working%20Files/FolderName')/Files('"
+workbookName+"')/$value");
but is there a way to retrieve it without the name? maybe by index?
Ive checked the documentation on https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest but saw no other examples on how else to retrieve files
Every file you upload into the Sharepoint will have the field Id mapped to it. This ID would be returned as part of the response whenever you create the file in the Sharepoint. This response would also return several links and fields related to the particular file you uploaded, in order to perform any operations on that file.
Using these fields such as Id, E-Tag you should be able to form another request to get the file name.
You can also find the request URL in the response you received after file creation.
In api automation, let's consider below code to hit the api and get response.
Response res= given().
formParam("email", "value").
formParam("password", "value").
formParam("action", "login").
header("token","value").
when().post("MyResource").then().assertThat().statusCode(200).extract().response();
Actually in the above code we're just building an api with formParams, header and resource with post request right!
so, there we have created 3 formParm manually and passed the values right? now i want that to added automatically based on no of parameters that we have from an excel sheet.
Thing is these parameters can be deleted or new parameters gets added in future, so that's why i want to add those dynamically from an excel sheet data.
how i can do that? any suggestions?
If i've understood you right, you want to have the parameters on the spreadsheet to use dynamically and on runtime.
To do that, you'll need to:
Read the spreadsheet file and get the parameters contained in a data structure such as a Map<String,String>, in which, the key is the field and the value is... the value :P
Iterate upon the data structure selected and set the formParam generically
final RequestSpecification given = given();
for(final Map.Entry<String,String> entry : map.entrySet()) {
given.formParam(entry.getKey(), entry.getValue());
}
final Response res = given.other_things() ...
I hope it helps, but keep in mind the use of Map is not necessary. Choose the data structure more appropriate to your situation!
I have a json array data file (pre-prepared) each item in the json array contain data which I want to be able to use in order to send a request to a server using the json array data file , i know how to be able to send one request after extracting data from the file but I am struggling of getting all the data to send one after another.
I want to imitate the following behavior which I wrote already in java:
List<Integer> mtl = Arrays.asList(new Integer[]{1, 9, 257, 265});
for(int i=0;i<jsonArray.size();i++){
JSONObject item = (JSONObject)jsonArray.get(i);
int dataFlagType = Integer.parseInt(item.get("DataFlagType").toString());
if(!(mtl.contains(dataFlagType))){
sendPushStream(Long.parseLong(m_ap.sid),pid,subsId,item,domain,dnsName,dataFlagType);
}else{
lastMessage = (JSONObject)jsonArray.get(i);
}
Thread.sleep(100);
}
Thread.sleep(100);
sendPushStream(Long.parseLong(m_ap.sid),pid,subsId,lastMessage,domain,dnsName,Integer.parseInt(lastMessage.get("DataFlagType").toString()));
where sendPushStream execute the post request itself.
I would suggest organizing your Test Plan as follows:
HTTP Request (Protocol: file, Path: /path/to/your/file.json
JSON Extractor (relevant JSONPath query to extract values and store them into JMeter Variables)
ForEach Controller to iterate the Variables coming from the JSON Extractor
HTTP Request - to mimic sendPushStream
Another option is using your Java code from JSR223 Sampler or JUnit Request sampler, just make sure you package your helper code as .jar and add it to JMeter Classpath
I have a Struts2 jsp page their i am sending one image, Temporary file path is comming to my java class after form submission but i do not know how can to save that path in db by changing it to Blob type.. Please consider this image columns is of blob type in my database table..
Here is the output what am getting in my Javaclass after the form submission:
My image path:
F:\Documents and Settings\software.netbeans\7.0\apache-tomcat-7.0.11_base\work\Catalina\localhost\AIGSA\upload__214d4f3e_136e8b74d9c__7fff_00000021.tmp 105542
filenames:
* Winter.jpg
Code:
for (File u: repImage)
{
System.out.println("*** "+u+"\t"+u.length());
}
int saveToDb= mo.addMembers(memberName, repImage);
How can I send my form Image to this {repImage Name, so that it will be easy to save it so my db
am not sure, but try:
int saveToDb= mo.addMembers( memberName, repImage.getBytes() );
If I understand your question properly, you want to store the binary data in your database. I'd say this is a bad idea in the first place for multiple reasons. A better method would be to reference a relative path that you can then use in your web application or the file system directly. Better yet, just store the reference to the location in Amazon/S3 where you want to save it/use it.
Regardless, to answer your question you would want to use ByteArrayOutputStream.