I'm currently using fluentd to write out log messages to a file with the file output plugin. Is there a way to use a field in the log message as a placeholder in the file name without specificing it as a chunked key?
No, unfortunately you can not.
https://docs.fluentd.org/output/file
https://docs.fluentd.org/configuration/buffer-section
Related
I am using Microsoft Graph to fetch mail and I recently noticed when an email has a .eml attachment, there are two cases:
If the sender attach that email through drugging emails to the composer, the attachment will be an item attachment type. <-- I can handle this case
If the sender attaches a .eml file through clicking "attach file", that attachment will be a type of file attachment. Up to this point, I think it is fine to be a file attachment. But when I try to fetch that attachment, the attachment content type is application/octet-stream which is wrong. Shouldn't it be message/rfc822? With application/octet-stream, I cannot create that attachment from our server.
It isn't wrong, application/octet-stream simply represents a generic/unknown binary file. From RFC 2046 ยง 4.5.1:
The "octet-stream" subtype is used to indicate that a body contains arbitrary binary data.
Your application can make its own determination on how to handle the file. In this case, the .eml is just a text file. You can simply fetch the attachment and treat it as raw text.
I am receiving a text file from a socket over TCP/IP. There is no file extension (or filename for that matter) as the data is received as bytes. I can take the data from this (in the form of NSData) and load it into a UITextView and display it fine.
I want to persist this data to a file. However, I don't know what format the data is in (txt, rtf, doc, docx)? I assume it as .txt and save it in the documents directory, but is there a programmatic way of finding out for sure? I've looked around StackOverflow and at the documentation and haven't been able to find anything.
And is there a way to get the details of the file attributes like the file creation date.
Thanks in advance.
When you send a file over a TCP/IP connection, only the file contents will be converted to data and be passed across. If you want the filename,extension and the file attributes, then you will have to add those details separately and append it with the data to be sent. Then you can parse it at the receiver end and use the results inside your app.
You can choose the file type you want when you save the data, you can get attributes from file,please refer to Get file creation date.
The flow is:
The user selects an image on the client.
Only filename, content-type and size are sent to the server. (E.g. "file.png", "image/png", "123123")
The response are fields and policies for upload directly to S3. (E.g. "key: xxx, "alc": ...)
The case is that if I change the extension of "file.pdf" to "file.png" and then uploads it, the data sent to the server before uploads to S3 are:
"file.png"
"image/png"
The servers says "ok" and return the S3 fields for upload .
But the content type sent is not a real content type. But how I can validate this on the server?
Thanks!
Example:
Testing Redactorjs server side code (https://github.com/dybskiy/redactor-js/blob/master/demo/scripts/image_upload.php) it checks the file content type. But trying upload fake image (test here: http://imperavi.com/redactor/), it not allows the fake image. Like I want!
But how it's possible? Look at the request params: (It sends as image/jpeg, that should be valid)
When I was dealing with this question at work I found a solution using Mechanize.
Say you have an image url, url = "http://my.image.com"
Then you can use img = Mechanize.new.get(url)[:body]
The way to test whether img is really an image is by issuing the following test:
img.is_a?(Mechanize::Image)
If the image is not legitimate, this will return false.
There may be a way to load the image from file instead of URL, I am not sure, but I recommend looking at the mechanize docs to check.
With older browsers there's nothing you can do, since there is no way for you to access the file contents or any metadata beyond its name.
With the HTML5 file api you can do better. For example,
document.getElementById("uploadInput").files[0].type
Returns the mime type of the first file. I don't believe that the method used to perform this identification is mandated by the standard.
If this is insufficient then you could read the file locally with the FileReader apis and do whatever tests you require. This could be as simple as checking for the magic bytes present at the start of various file formats to fully validating that the file conforms to the relevant specification. MDN has a great article that shows how to use various bits of these apis.
Ultimately none of this would stop a malicious attempt.
I had use a method to redirect all my logs into a text file. The problem is that i do not know how to store the text file into the SQLite database.
I would use Blob fields. here is a description how to do it. And of course the content of the file should be stored. The file itself can be stored elsewhere, with a HTTP POST...
I am using paperclip to attach an excel file to a mode.
The purpose is to import the data from the excel file to the database.
Model: Import
has_attached_file: spreadsheet
For the import process, I want to access the file in my model as following.
path = "#{Rails.root}/public/#{spreadsheet.url}"
This doesn't work. I guess because the url has the timestamp at the end.
In general what is the best way to access the attachments on server side ?
I think you're looking for the to_file method. You should be able to do something like this:
excel_file = self.spreadsheet.to_file
which will either return the uploaded file from the server (if you're using s3 or remote storage), or if it has been assigned to the model but not actually stored yet (if you haven't called model.save since it was uploaded), it returns the temp file stored on disk.
From there you should be able to use an excel gem or library to parse the contents.
Alternatively, you can use spreadsheet.url(nil, false) - the second parameter denotes whether or not to append a timestamp.
#spreadsheet.path
http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Attachment#path-instance_method