I'm using Services 3 to create a custom service that will create or update a specific content type (similar to the built-in Node Service). The content type uses CCK for a few fields, mainly an image (file) upload field. I have no problem connecting to the service and creating a new node by setting the text parameters (including some CCK fields), but I can't figure out how to handle submitting a file.
I've tried base64 encoding the jpg then passing it as a parameter using the same field name as the node creation form uses, files[field_um_high_res_0]. I've also tried submitting a multipart form.
Any ideas?
Thanks,
Howie
Looks like all I had to do was encode the file as base64 then use the file resource to create a new file in the system and take the resultant fid and use it to load the new file object which is passed as the value of the CCK file field.
So it looks like this:
my_cck_file_field_name[0] = the_file_object
Related
Here is what i am trying to do
Get a file and encode it to base 64
Login to API and get OAUTH token for subsequent API calls (Since Invoke HTTP doesnt take a body so i have to pass a body using GenerateFlow processor before that)
Both Steps 1 and 2 are interchangeable
Now i need the token from the login call as Header value and Base64 encoded file as the body to the next Invoke Processor.
The problem is i am not able to connect the flows 1 and 2 so i can take them to step 3 where i need to invoke another API using the data from the 2. Both GetFile and GenerateFlow are source processors.
Here is what i am thinking, to somehow convert the content to attribute. Since the file is encoded in base64, is there a way i can convert that content to attribute? i am trying to but the content is just random text, i am not sure what param to look for or what i need to put that to. is there a way to say convert whatever is in the content to an attribute say filecontent="all the flow-content"
nifi-flow-snapshot
Base 64 encoded content
First trigger both flow fro mthe same generateflowfie >> updateattribute(create common attribute to be used in merge correlation).
Do your work
Use MergeContent - keep all unique attribute - Set correlaion using the common attribute set in out first step.
This is how i resolved my issue for now. There may be other better ways but this one worked.
Start the flow with
GetFile>>Base64Encode>>ExtractText>>ReplaceText>>Login>>continue
with rest of the flow
The trick that work was to place the ReplaceText so it can grab the entire base64 encoded content and place it in an attribute. then ReplaceText will replace the entire content with the body of the login processor.
Now i have both login token and base 64 encoded file which i can send to my next processors.
Thanks
Which attribute can be used to pass the File Name while ingesting a document?
How to determine the file type when a document is pulled from Documentum using DFC API
Once a file is uploaded to Documentum, it "loses" its filename. A document is linked to a content object, which is again linked to the file itself on a filestore.
There are ways to get hints about the original filename and/or file extensions:
Find the Content ID by looking at i_contents_id, and look at that object's set_file attribute. Normally, this string will contain the full path to path (including filename) of the original file, but there are no guarantees.
If storage extensions are on (yes, they're on by default), you could use the following API command to get the file extension: getpath,c,<doc_id>
The document's a_content_type links to the name attribute of a dm_format object. Look at that object's dos_extension attribute to see the registered file extension for that given format (there is no guarantee that this was the original file extension, however).
As for which attribute should contain the filename, there is no clear answer. It's all up to the client. Normally, using object_nameshould suffice, or you could create a custom type with a custom attribute if the original filename is very important to you.
File in Documentum repository don't need to have document names that is originating from file that was uploaded from file system.
When you export document via export action with WDK application, i.e. Documentum Administrator or Webtop exported file will have name based on the value that was place in object_name property of that specific object.
File type of the content that is related to sepecific document object in repository is written in attribute a_content_type. Values in this attribute are internal Documetnum notation but names are intuitive. Check this question for more info or google.
I've been working on creating my own email client. I'm already successfully displaying attachments and embedded images via data URI. I was wondering once stored in a data if there was any way for me to assign data such as an image to a variable in client-side code (be it XHTML, JavaScript, JSON, etc) so I only have to send a single copy to the client from the server saving bandwidth though be able to display that content (again, such as an image) multiple times?
Pure JavaScript, no frameworks or libraries.
Also the main goal is to transfer the data only once from the client to the server. Once in the DOM it's perfectly okay if we end up having two img elements in example.
As a bonus, I'd like to use two img elements but with the DOM still reference the same single data-uri if possible thus saving memory at the client.
I was wondering once stored in a data if there was any way for me to assign data such as an image to a variable in client-side code
Use one of the following techniques:
Embed the data URI in an SVG element, then dereference it as a background-image URL
Embed the data URI in a script element, then dereference it as a dataset property
Store the data URI in a documentFragment, then wrap it in a function
References
CSS Wikibook:Data-URIs
HTMLElement.dataset
play .wav sound file encoded in base64 with javascript
Saving the image in a web directory and storing the URL in the database using this approach, I stored the image URL in the database. Based on that image id (I need to pass this image id to the controller from an Ajax call). I need to retrieve the image.
I got the image id using a jQuery template, so I have passed that image id to the controller. What should I write in the controller, filepathresult or fileresult? Or is there another approach?
OK, you're a bit confused.
You have the actual image file, file.jpg and you have the physical path to the file, D:\some\path\to\file.jpg.
You have the URL path to the file and a surrogate identity (your id).
id: 1337 (some random number)
URL: ????
First question:
You say you're storing the URL. Is it really the complete URL? Is it just a partial path to the image? Is the path from the root of the website or the root of the application? Is it just a partial physical path?
Second question:
What are you actually trying to do?
Do you just want to get the full path to the image? Why do you need Ajax to do this, if you already have the id? You might want to rethink how you're storing the images if any performance needs to come out of this.
Once an image gets a new identity, it often makes sense to use that new identity everywhere; you might ought to consider copy/rename the file for the new identity after it's uploaded (and possibly save the old filename for record keeping purposes). If you need to keep the file names (more or less) as-is, however, it'd be better to provide the ability to grab the URLs for a whole set of ids rather than to individually make an Ajax request id-by-id.
If you request a resource (AKA navigate to a URL) that has a physical file, IIS is going to serve it directly (that is, if you ask for www.mysite.com/Images/Image3.jpg IIS is going to serve it directly). I really don't understand exactly what you are doing, but if you mean that you get the associated URL for an image using an Ajax call to an MVC controller with the id of the image, you could do several things.
You could simply return the URL and use JavaScript code to create an image tag with that URL and inserting it in the DOM.
You could return a view like <img src="{yoururl}" /> and insert it in the DOM using JavaScript.
You could store the images on the database directly and use the File method to return the image bits indicating the correct MIME type.
I'm using Spring 3 ability to upload a file. I would like to know the best way to validate that a file is of a certain type, specifically a csv file. I'm rather sure that checking the extension is useless and currently I am checking the content type of the file that is uploaded. I just ensure that it is of type "text/csv". And just to clarify this is a file uploaded by the client meaning I have no control of its origins.
I'm curious how Spring/the browser determines what the content type is? Is this the best/safest way to determine what kind of file has been uploaded? Can I ever be 100% certain?
UPDATE: Again I'm not wondering how to determine what the content type is of a file but how the content type gets determined. How does spring/the browser know that the content type is a "text/csv" based on the file uploaded?
You can use
org.springframework.web.multipart.commons.CommonsMultipartFile object.
it hasgetContentType(); method.
Look at the following example http://www.ioncannon.net/programming/975/spring-3-file-upload-example/
you can just add the simple test on CommonsMultipartFile object and redirect to error page if it the content type is incorrect.
So you can also count the number of commas in the file per line.There should normally be the same amount of commas on each line of the file for it to be a valid CSV file.
Why you don't just take the file name in you validator and split it, the file type is fileName.split("\.")[filename.length()-1] string
Ok, in this case i suggest you to use the Csvreader java library. You just have to check your csvreader object and that's all.
As far as I'm aware the getContentType(String) method gets its value from whatever the user agent tells it - so you're right to be wary as this can easily be spoofed.
For binary files you could check the magic number or use a library, such as mime-util or jMimeMagic. There's also Files.probeContentType(String) since Java 7 but it only works with files on disk and bugs have been reported on some OSes.