Preventing duplicate files in a SQL Server 2014 FileTable - sql-server

I'm planning to write a ASP.NET MVC app that will upload large files (possibly as large as 500 MB) to a SQL Server 2014 FileTable. Is there some way to check if the file already exists in the FileTable before uploading?
If the file already exists in the database, then I will want to reference the already-uploaded file instead of uploading a new one.
If the file must first be uploaded to the FileTable before checking whether the file already exists in the FileTable, what's the recommended way to do the comparison? (Should I do some sort of separate CRC generated for each file and then compare against that?)
Thanks!

You will have to calculate the hash of the file on the client side before uploading it. I don't have the pieces of code, only the concepts:
using the HTML File API, and the File Reader to read the file
with a Javascript implementation of SHA256 compute the hash of the file
on your server you store the file contents, as well as the SHA256 hash of each file
client performs an AJAX request to see if the a file with this hash already exists
if it doesn't already exist: Upload it!

Related

Can anyone suggest me how i can write the path to store the output file in which my stored procedure outputs in my oracle DB?

suppose the IP address of my FTP server is xx.xxx.xx.xx and i need the output file to be stored in D:/example. I need to esnure that the path i give is in my FTP server. How can i include that in my fopen function, like a path which points to the example in my FTP server.
Generally speaking, this is how it goes:
there's a database server
there is a directory on one of its disks
that directory will be used in create directory command which creates a directory, Oracle object
it will be used as a target for your file-related operations. For example:
it'll contain CSV files which are source of external tables
.dmp files, result of data pump export, will be stored there (the same goes for import)
UTL_FILE will create files in that directory
All that means that your idea of creating a file on a FTP server might not work just as easy.
However, there's a way : if you create directory (Oracle object) using UNC (Universal Naming Convention) which points to a directory on the FTP server, the file might be created there. Do some research about it; I know I once did that (put files onto an application server), but that was long time ago and I don't remember everything I did.
Another option you might consider is DBMS_SCHEDULER package. Suppose you create a file on the database server (which is the simplest option; if you do it right, it is more or less trivial). Once the procedure (which creates the file) is done, call DBMS_SCHEDULER.CREATE_JOB using the executable job type and call an operating system batch file that will copy the file from the database server to the FTP server.
That's all I can say about it; at least, you have something to research & think about.

Oracle RDS (AWS): How to retrieve files generated?

Here's the situation, we have a store procedure that generates .txt files in a directory inside of a database. I recently migrated from Oracle DB SE on Linux to an RDS oracle database instance.
I know I'm not able to access files remotely (no scp, or sftp) to copy the files that it generates, so instead of I decided to use DBMS_FILE_TRANSFER.PUT_FILE using a DB link to another database.
The link is working fine, but whenever I try to copy the file I get the following error:
ERROR at line 1:
ORA-19505: failed to identify file "/u01/test.txt"
ORA-27046: file size is not a multiple of logical block size
Additional information: 1
Is there any alternatives to do this without using an EC2 instance?
File size must be a multiple of 512 (or whatever you've set the logical block size to)
Ensure when the file is made that the size is exactly a multiple of 512, pad with zeros or similar to ensure this
See https://asktom.oracle.com/pls/apex/asktom.search?tag=file-transfer

Using SQL Server to Zip Files

I have a table that stores users FileData as such Data Type: varbinary(MAX) FILESTREAM null
In my web application, the user selects multiple file Ids and eventually wants a zip file of those selected FileIds
Currently my solution is to bring the FileData into C# and call some C# function/library that zips the file and returns that to the user. The problem with this is that the user could potentially select a ton of files causing a lot of temporary data to exist in C#.
Is there a way that I can zip these files in SQL Server and then return the zipped result to C# without having to bring the selected FileDatas into C# memory?
You can certainly do this through a stored procedure, which would write the files and zip, but you would be writing SQL which writes files to disk and executes windows system commands. You can read up on xp_cmdshell. I would advise against this personally
You are still going to have a large zip file blob coming back to your server in that model. Couldn't your users still overload your system? You would get around this using streaming which could be done with your zipping.
Are you using the most recent ZipArchive? It provides streaming access both in and out if used properly. See here for an example writing without bumping into memory Basically you will write your code to use an output stream so that data doesnt build up in memory ...new ZipArchive(myOutPutStream, ZipArchiveMode.Update, true or false)

return a file from a directory using sql

I am writing an add-on to a current system and need to get image data. However the image data gets saved in a directory on the server side of the client/server application. I want to read the file from the directory and return it as an image field using SQL Server which is also on the Server.
Is this at all possible?
Write a CLR storedprocedure (c#) which reads the contents of the image file and returns it as a varbinary(MAX).

SQLite database file created from JDBC?

I have created a SQLite database from Java. Now I want to know where it is stored physically on disk, so that I can push that file on to Android.
You specified a database name as part of the JDBC connection URL. Look for a file with that name on your harddisk. Example:
jdbc:sqlite:test.db
-> look for test.db
SQLite usually produces one file with the extension .sqlite, but this is just convention, the extension can be anything.
As already was said, the code which opens the database spefifies the path where the file should be stored, so you have to look there.

Resources