Is there a way to retrieve file from SharePoint without file name? - java

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.

Related

How to upload encoded metadata to sharepoint using ValidateUpdateListItem method?

I am trying to upload metadata to SharePoint server using ValidateUpdateListItem method. In this method, value of bNewDocumentUpdate is true to avoid creating a new version for the uploaded file. The name of metadata which has to be updated, is 'cc1'. When i fetch metadata information, the name of metadata is converted from 'cc1' to 'OData__x0063_c1'. Now, i have used both the names (encoded and decoded) to upload the metadata, but below error is generated -
{"error":{"code":"-2147024809, System.ArgumentException","message":{"lang":"en-US","value":"Column 'cc1' does not exist. It may have been deleted by another user. /Shared Documents"}}}
Earlier, i was not using ValidateUpdateListItem method, and was able to upload metadata using encoded name.
Is there any way to upload the encoded metadata while using ValidateUpdateListItem method?
Update -
This problem has been resolved by using 'InternalName' of metadata. Earlier i was using 'EntityPropertyName' of metadata to set metadata value.

SDMX-ML: SAS libname XML

Eurostat data can be downloaded via a REST API. The response format of the API is a XML file formatted according to the SDMX-ML standard. With SAS, very conveniently, one can access XML files with the libname statement and the XML or XMLv2 engine.
Currently, I am using the xmlv2 engine together with the automap= option to generate an xmlmap to access the data. It works. But the resulting SAS data sets are very unstructured, and for another data set to be downloaded the data structure might change. Also the request might depend on the DSD-file that Eurostat provides for each database item within a different XML file.
Here comes the code:
%let path = /your/working/directory/;
filename map "&path.map.txt";
filename resp "&path.resp.txt";
proc http
URL="http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011"
METHOD="GET"
OUT=resp;
run;quit;
libname resp XMLv2 automap=REPLACE xmlmap=map;
proc datasets;
copy out=WORK in=resp;
run;quit;
With the code above, you can view all downloaded data in your WORK library. Its a mess.
To download another time series change parameters of the URL according to Eurostat's description.
So here is my question
Is there a way to easily generate a xmlmap from a call to the DSD file so that the data are stored in a well structured way?
As the SDMX-ML standard is widely used in public institutions such as the ECB, Eurostat, OECD... I am wondering if somebody has implemented requests to the databases, already. I know about the tool from Banca Italia which uses a javaObject. However, I was wondering if there might be a solution without the javaObject.

How to read file content values in file array

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.

ckan add source url using java client

I am trying to add the source URL on an existing resource but I can't get it to work.
This is what I have:
HttpEntity reqEntity = MultipartEntityBuilder.create()
.addPart("id", new StringBody("resource id",ContentType.TEXT_PLAIN))
.addPart("Source", new StringBody("www.google.com",ContentType.TEXT_PLAIN))
.build();
postRequest = new HttpPost(host+"/api/3/action/resource_update");
postRequest.setEntity(reqEntity);
postRequest.setHeader("X-CKAN-API-Key", "myApi");
Which gives me the following error:
"success": false, "error": {"__type": "Validation Error", "url": ["Missing value"]}
I can add a Source field when I upload a file, but it doesn't create a link for it. Maybe because I use ContentType.TEXT_PLAIN instead of something that will tell CKAN that this is a link?
Edit:
By source I mean the link on the resource information where it points to the webpage of the original data. When manually uploading a file you have that option, I just cant get it to work with the API.
The error is telling you that you've not specified the url value for the resource, which is necessary.
The content that you POST needs to be in JSON format, whereas you appear to be sending it as multipart form data.
The JSON keys you need to send for a resource are id, url, name, format etc. i.e. you need to set url rather than Source. You can see the existing keys by looking at /api/action/resource_show?id=xyz.
The normal way to use resource_update is to do resource_show first, edit the JSON with the new values, and then resource_update. That way you don't lose any other properties of the resource, such as format.

Send Mulitpart file from Controller to JSP (Spring)

My requirement is to upload a JPEG/PDF file & save it as BLOB.
We have done it. But if server side error occurs which redirects to JSP page, I will get all data (e.g. input fields, drop downs, checkbox, etc.) except file.
Then again I need to choose a file.
Is there any way to preserve a file or send a file from controller to JSP.
No it is not possible.
The simplest workaround is to keep the uploaded file in session so that you can recover it during the next form submission. Take care to users working with several tabs/windows: use a session key that clearly identifies the form on which the user is working. You could for example generate a unique identifier that you then store in a hidden field of the form.
To be able to download it again, you would need to provide second mapping that retrieves the file from the session.
MultipartFile inputFile = fileUploadBean.getFile();
HttpSession session = request.getSession();
if(!(inputFile.isEmpty())) {
session.setAttribute("inputFile", inputFile);
}
logger.info("inputFile : " + session.getAttribute("inputFile"));
if(inputFile.isEmpty() && session.getAttribute("inputFile")!=null) {
inputFile = (MultipartFile)session.getAttribute("inputFile");
}
This is what I did.

Categories