Added stub to PDF upload handling (and package dependencies)
This commit is contained in:
@@ -2,7 +2,7 @@ Package: swarmops-frontend-internal
|
||||
Version: --BuildNumber--
|
||||
Architecture: all
|
||||
Maintainer: Rick Falkvinge (swarmops-maintain@falkvinge.net)
|
||||
Depends: swarmops-common-internal, apache2 (>= 2.2.20), mono-apache-server2 (>= 2.10-1), libapache2-mod-mono (>= 2.10-1), libgdiplus (>= 2.10-3)
|
||||
Depends: swarmops-common-internal, apache2 (>= 2.2.20), mono-apache-server2 (>= 2.10-1), libapache2-mod-mono (>= 2.10-1), libgdiplus (>= 2.10-3), imagemagick, ghostscript
|
||||
Conflicts: swarmops-frontend
|
||||
Homepage: http://swarmops.com/
|
||||
Description: Swarmops Frontend
|
||||
|
||||
@@ -2,7 +2,7 @@ Package: swarmops-frontend
|
||||
Version: --BuildNumber--
|
||||
Architecture: all
|
||||
Maintainer: Rick Falkvinge (swarmops-maintain@falkvinge.net)
|
||||
Depends: swarmops-common, apache2 (>= 2.2.20), mono-apache-server2 (>= 2.10-1), libapache2-mod-mono (>= 2.10-1), libgdiplus (>= 2.10-3)
|
||||
Depends: swarmops-common, apache2 (>= 2.2.20), mono-apache-server2 (>= 2.10-1), libapache2-mod-mono (>= 2.10-1), libgdiplus (>= 2.10-3), imagemagick, ghostscript
|
||||
Conflicts: swarmops-frontend-internal
|
||||
Homepage: http://swarmops.com/
|
||||
Description: Swarmops Frontend
|
||||
|
||||
@@ -151,13 +151,23 @@ namespace Swarmops.Frontend.Automation
|
||||
HttpPostedFile file = context.Request.Files[i];
|
||||
string fullName = Path.GetFileName (file.FileName);
|
||||
|
||||
// Store in MemoryStream in order to try to load as an image
|
||||
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture (context);
|
||||
|
||||
Person uploadingPerson = authData.CurrentUser;
|
||||
Organization currentOrg = authData.CurrentOrganization;
|
||||
|
||||
|
||||
bool convertPdf = false;
|
||||
|
||||
if (file.FileName.ToLower().EndsWith(".pdf"))
|
||||
{
|
||||
convertPdf = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// If not PDF, try to load as an image
|
||||
|
||||
/*
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] fileData = new byte[file.ContentLength];
|
||||
@@ -171,9 +181,14 @@ namespace Swarmops.Frontend.Automation
|
||||
try
|
||||
{
|
||||
Image image = Image.FromStream (file.InputStream);
|
||||
image.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// TODO: If general files accepted, then ok, otherwise fuck off
|
||||
|
||||
// TODO: Accept general files
|
||||
|
||||
var errorStatus = new FilesStatus (fullName, file.ContentLength);
|
||||
errorStatus.error = "ERR_NOT_IMAGE";
|
||||
errorStatus.url = string.Empty;
|
||||
@@ -184,6 +199,7 @@ namespace Swarmops.Frontend.Automation
|
||||
// -1 for length means the file was NOT saved, and that it could not be parsed as image.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string guid = context.Request.QueryString["Guid"];
|
||||
|
||||
@@ -221,11 +237,36 @@ namespace Swarmops.Frontend.Automation
|
||||
"File name determination failed; probable file system permissions error");
|
||||
}
|
||||
|
||||
file.InputStream.Position = 0;
|
||||
file.SaveAs (StorageRoot + fileFolder + Path.DirectorySeparatorChar + fileName);
|
||||
string relativeFileName = fileFolder + Path.DirectorySeparatorChar + fileName;
|
||||
|
||||
Document.Create (fileFolder + Path.DirectorySeparatorChar + fileName, file.FileName, file.ContentLength,
|
||||
guid, null, authData.CurrentUser);
|
||||
file.InputStream.Position = 0;
|
||||
file.SaveAs (StorageRoot + relativeFileName);
|
||||
|
||||
if (convertPdf)
|
||||
{
|
||||
// Convert PDF file into a series of PNG images, one per page
|
||||
|
||||
int pageCounter = 0;
|
||||
|
||||
// TODO: ShellExecute ImageMagick Convert
|
||||
|
||||
string testPageFileName = String.Format("{0}-{1:D4}.png", relativeFileName, pageCounter);
|
||||
|
||||
while (File.Exists (StorageRoot + testPageFileName))
|
||||
{
|
||||
Document.Create (fileFolder + Path.DirectorySeparatorChar + fileName, file.FileName, file.ContentLength,
|
||||
guid, null, authData.CurrentUser);
|
||||
|
||||
pageCounter++;
|
||||
testPageFileName = String.Format("{0}-{1:D4}.png", relativeFileName, pageCounter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Document.Create (fileFolder + Path.DirectorySeparatorChar + fileName, file.FileName, file.ContentLength,
|
||||
guid, null, authData.CurrentUser);
|
||||
|
||||
}
|
||||
|
||||
statuses.Add (new FilesStatus (fullName, file.ContentLength));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user