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.
Related
I am storing object which consists of stream and metadata in s3 using aws java sdk v2.
Metadata is a map of values extracted from object received from UI.
My code looks this
response=s3Client.putObject(PutObjectRequest.builder().bucket(bucket).key(key).metadata(metadata(media)).build(),
RequestBody.fromBytes(readAsBytesFromStream(media)));
I want to retrieve only the meta information from the object saved and not read the object's payload.
The use case is i have to read only the meta info to render on UI preventing s3 to read object's content.
Is there any way where i can read only the meta info and not the content of saved object.As reading multiple object's content(payload+metadata) and then rendering would make it slow.
Some other way to store meta and payload separately so that reading meta becomes efficient .
You should be able to use the headObject method.
Something like:
response = s3Client.headObject(PutObjectRequest.builder().bucket(bucket).key(key).build();
metadata = response.metadata();
SDK documentation:
https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3Client.html#headObject-java.util.function.Consumer-
https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/model/HeadObjectResponse.html
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.
I'm developing a Java application which executes the following methods with Account SAS (Shared Access Signature) URI:
CLoudBlockBlob blob = container.getBlockBlobReference("tmp/test.json");
blob.exists();
blob.openInputStream();
blob.delete();
container.exists();
container.listBlobs().iterator().next();
container.getDirectoryReference("tmp/").listBlobs().iterator().next()
But, I could not find a way to generate a single Account SAS to support all methods listed above.
Account SAS generated with SharedAccessAccountResourceType.OBJECT:
Executes successfully:
CLoudBlockBlob blob = container.getBlockBlobReference("tmp/test.json");
blob.exists();
blob.openInputStream();
blob.delete();
Fails with an error code: AuthorizationResourceTypeMismatch
container.exists();
container.listBlobs().iterator().next();
container.getDirectoryReference("tmp/").listBlobs().iterator().next()
Account SAS generated with SharedAccessAccountResourceType.CONTAINER:
Executes successfully:
container.exists();
container.listBlobs().iterator().next();
container.getDirectoryReference("tmp/").listBlobs().iterator().next()
Fails with an error code: AuthorizationResourceTypeMismatch
CLoudBlockBlob blob = container.getBlockBlobReference("tmp/test.json");
blob.exists();
blob.openInputStream();
blob.delete();
Account SAS generated with SharedAccessAccountResourceType.SERVICE
fails with an error code: AuthorizationResourceTypeMismatch for all methods above.
Is there any way to generate a single Account SAS which work for all following methods?
CLoudBlockBlob blob = container.getBlockBlobReference("tmp/test.json");
blob.exists();
blob.openInputStream();
blob.delete();
container.exists();
container.listBlobs().iterator().next();
container.getDirectoryReference("tmp/").listBlobs().iterator().next()
Yea just add the right permissions on the blob and container resources. Note that list is different from the create.
You can find it here
And then add permissions
For listing blobs in a blob container, you would need to set resource type as Container. The permission you would need would be List.
For checking if blob exists, you would need to set resource type as Object. The permission you would need would be Read.
For deleting blob, you would need to set the permission as Delete. The resource type would still be Object.
Since you're working with just Blob Storage, the service type would be just Blob.
To summarize:
Service Type: Blob
Resource Types: Container (for listing blobs), and Object (for checking blob's existence and deleting blob)
Permissions: List, Read, and Delete
With this you should be able to accomplish your goal.
Setting both resource types resolved the issue:
sasAccountPolicy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.OBJECT, SharedAccessAccountResourceType.CONTAINER));
(The application which I'm developing also has to generate SAS URI.)
Thanks.
How to upload an image and saved into the database and that image should be shown on the user profile page? The image can be of any type jpg, jpeg and png. I am using JSP, jQuery and Spring MVC framework and Java and Spring data jpa.
I am not using servlet in my application. I am new to this field and not able to complete it.
You need a VARBINARY column to contain the image. Open the file using an InputStream, load byte[]s from it, and write that into the column.
You need another column to save the mime file type. You can obtain the file type with java.nio.file.Files.probeContentType( Path path )
In your response headers, you need to:
Use setContentLength() to set the length of the file.
Use setContentType() to set the mime image type.
If your database offers a means to create an InputStream on a varbinary column, use it. Otherwise, you need to read the contents of your varbinary column into a byte[], and then create a ByteArrayInputStream on the byte[].
Finally, you need to construct a response entity using the constructor that accepts an input stream: return new ResponseEntity(inputStream, httpHeaders, HttpStatus.OK);
I have never saved and retrieved an image to and from the database before. I wrote down what I guessed would be the process. I would just like to know if this is correct though:
Save image:
Select & Upload image file from jsp (Struts 2) which will save it as a .tmp file.
Convert the .tmp file to a byte[] array (Java Server-Side)
Store the byte[] array as a blob in the database (Java Server-Side)
Get image:
Get the byte[] array from the database (Java Server-Side)
Convert the byte[] array to an image file (Java Server-Side)
Create the file in a location (Java Server-Side)
Use an img tag to display the file (JSP Client-Side)
Delete the file after it's finished being used? (Java Server-Side)
I'm aware of the fact that it is highly recommended to not save & retrieve images to and from the database. I would like to know how to do it anyway.
Thanks
Almost correct.
It's expensive and not so great to create the file on the fly and then delete it.
Yes, you store it as the raw bytes in the database, but the way to retrieve it and display it to a client machine is to implement a web handler that sets the content-type of the response to the appropriate MIME type and then dumps the bytes out to the response stream.
Yes, You get it right.
Save Image :
The decision to save image is very much dependent on further usage. You have one option to save the file on the file system. The location for saved file should be saved into the metadata in the database table.
Get Image:
You do not have to right file data on any temp location. It can be easily rendered from the database only. Just send a request from client and intercept that request in a spacial designed Servlet. This Servlet will read the file metadata and corresponding file, if successful, write the file back on the response stream.