Size limit on ContentVersion object in Salesforce - file-upload

I was trying to create and insert a ContentVersion object in Salesforce lightning(for file upload) using the following code:
ContentVersion v = new ContentVersion();
v.versionData = EncodingUtil.base64Decode(content);
v.title = fileName;
v.pathOnClient = fileName;
insert v;
This works fine for smaller files. But when i try loading a file which is just 750KB the above operation fails(actual allowed size could be still less).
Is there any limit on the size if the files that could be uploaded using the above code?

As per the similar question from the Salesforce StackExchange.
From Base Lightning Components Considerations:
When working with type="file", you must provide your own server-side logic for uploading files to Salesforce. [...]
Uploading files using this component is subject to regular Apex controller limits, which is 1 MB. To accommodate file size increase due to base64 encoding, we recommend that you set the maximum file size to 750 KB. You must implement chunking for file size larger than 1 MB. Files uploaded via chunking are subject to a size limit of 4 MB.
The Base64 is pushing the file size past the Maximum HTTP POST form sizeā€”the size of all keys and values in the form limit of 1 MB. Or at least this seems like the applicable limit here.
Instead you will need to go with either an embed Visualforce page as used in How to Build a Lightning File Uploader Component. This gets you up to the Maximum file size for a file uploaded using a Visualforce page limit of 10 MB. Just remember to keep the file processing to a minimum before the heap size limit catches up with you.

Related

Google Drive - use WebViewLink vs thumbnailLink

I'm using the Google Drive API where I can gain access to 2 pieces of data that I need to display a jpg file oin my program. WebViewLink is the "large" size image while thumbnailLink is the "thumb" smaller size of the same image.
I'm having an issue with downloading the WebViewLink that I do not have with the thumbnailLink. Part of my code calls either exif_imagetype($filename) or getimagesize($filename) so I can retrieve the type, height & width etc for the $filename. This is successful for the thumbnailView but not the WebViewLink...
code snippet...
$WebViewLink = "https://drive.google.com/a/treering.com/file/d/blablabla";
$type = exif_imagetype($WebViewLink);
--- results in the error
"PHP Warning: exif_imagetype(): stream does not support seeking..."
where as...
$thumbnailLink = "https://lh6.googleusercontent.com/blablabla";
$type = exif_imagetype($thumbnailLink);
--- successful
where $type = 2 // a .jpg file
Not sure what I need to do to gain a usable WebViewLink... maybe use the "export" function to copy to a file on my server that is accessible, then use that exported file for the functions that fail above?
Thanks for any help.
John
I think you are using the wrong property to get the image of the file.
WebViewLink
A link for opening the file in a relevant Google editor or viewer in a browser.
thumbnailLink
A short-lived link to the file's thumbnail, if available. Typically lasts on the order of hours.
You can try using the iconLink():
A static, unauthenticated link to the file's icon.
Sample image of thumbnailLink:
Sample image of a iconLink:
It will still show relevant image about the file.
Hope it helps!

org.apache.commons.fileupload.FileUploadBase and SizeLimitExceededException

I am trying to upload a file in my application. The file size is of 2055 kb. After uploading the file. It throws an exception is:
04-Feb-2016 15:42:41.141 INFO [http-nio-8084-exec-78] com.opensymphony.xwork2.util.logging.commons.CommonsLogger.info Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir
04-Feb-2016 15:42:41.203 WARNING [http-nio-8084-exec-78] com.opensymphony.xwork2.util.logging.commons.CommonsLogger.warn Request exceeded size limit!"
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (2104281) exceeds the configured maximum (2097152)
I am using Struts Framework.
Struts2 allows to configure the limits for uploaded file(s).
The Struts 2 default.properties file defines several settings that affect the behavior of file uploading. You may find in necessary to change these values. The names and default values are:
struts.multipart.parser=jakarta
struts.multipart.saveDir=
struts.multipart.maxSize=2097152
Note, without 0 at the end.
You can change this by setting a constant to increase a request limit
<constant name="struts.multipart.maxSize" value="20971520" />
Please remember that the struts.multipart.maxSize is the size limit of the whole request, which means when you uploading multiple files, the sum of their size must be below the struts.multipart.maxSize!
There's also a limit on individual file that you can change by overriding the action config
<interceptor-ref name="fileUpload">
<param name="maximumSize">20971520</param>
</interceptor-ref>
More in formation about File Upload you can find on the docs page.

MVC4 - How to upload a file partially (only the first 10 lines, for e.g.)

ASP.NET MVC - Is it possible to upload only the first 10 lines of a file? Basically, we have some files that can range from 1-10GB but the data that we need is present only in the first 10 rows in the file. Using the typical web development approache, we'd upload the whole file to the server and then read the first 10 rows, but uploading a 10GB file just to read a few bytes of data seems a big waste of resources. Is it possible to read such a file without uploading all of it to the webserver?
Solution - FileAPIs slice function solved this problem (thanks to Chris below). The simplified code is below for anyone interested -
var sampleFile = document.getElementById('yourfileelement').files[0];
var reader = new FileReader();
var fileData = sampleFile.slice(0, 500000); //Read top 500000 bytes
reader.onprogress = function (evt) { //Show progressbar etc }
reader.onloadend = function (evt) { alert(evt.target.result); } //evt.target.result contains the file data that was read
reader.readAsText(fileClientReadData);
No, but you may be able to accomplish it using the File API client-side to read and send to the server via AJAX just the first 10 lines. However, note that the File API is only supported in modern browsers, so this won't work with IE 9 or less. You might be able to create a more comprehensive solution using a Flash or Java applet, but ugh.

Can't replace mongo document

I am attempting to save documents to a mongoDB cluster (sharded replica sets) and am having a strange issue. I am using pymongo 2.7.2 and TokuMX 1.5 mongodb 2.4.10.
When I attempt to save (overwrite) existing documents I am getting an exception that looks like the document I am saving is too large:
doc = db.collection.find_one()
db.collection.save(doc)
pymongo.errors.OperationFailure: BSONObj size: 18798961 (0x71D91E01) is invalid. Size must be between 0 and 16793600(16MB) First element: op: "u"
However this works fine:
doc = db.collection.find_one()
db.collection.remove({'_id': doc['_id']})
db.collection.save(doc)
The document in question is about 9mb, so it looks like when I attempt to replace the document it is somehow doubling the size of the document, exceeding the 16mb limit.
Any ideas as to what could cause this behavior?
Apparently this is a known issue with TokuMX. Oplog entries are twice the size of the document, so replacing a 9mb document will result in a 18mb oplog entry- which raises the exception.
The solution would be to limit document writes to less than 8mb so that oplog entries never exceed 16mb.
I think this is a side effect of how save is implemented in PyMongo.
Under the hood if the document has a _id then the save(doc) is turned into an update(doc, doc). That is where the doubling is coming into play since the query+update is 18MB.
When you removed the _id you changed the save(doc) into a insert(doc) of a new document with a new _id. I don't think that is what you wanted.
Rather than use save I would recommend constructing a query with just the _id field from the original document and doing the update call manually. I would even go so far as you should enter a Jira ticket to get PyMongo to do this for you.
HTH,
Rob.

File upload and save file info to database in silverlight

I know that out there a lots of posts but i coudn't find a example on how i can uload a video to server and save fileinfo to sql database. I am looking for a silverlight example. Video size would be arround 100-200 Mb.
If someone can point in the right direction , i would apreciate.
You have to split the file and upload by chunk.
The steps :
In a cancelable thread : BackgroundWorker ;
Split your file by chunk : FileStream.Read (Just read chunk one by one) ;
Send the file chunk : HttpWebRequest with a upload ID ;
Wait until the chunk is sent : AutoResetEvent ;
Run the next chunk (step 2).
At the end you can use a Hash like md5 to test if your file is not corrupted.
You can send many chunk in the same time with an order parameter and, in the server side, reorder the chunk.
Note : You can find a sample by reading the project Silverlight File Uploader.