Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing an app where, I can enter URL of a mp3 file from web and when i click download, the app will download it in the app. Can someone help me ?
I am new to ios development. I am trying to learn Swift
Xcode 8 • Swift 3
if let audioUrl = URL(string: "http://freetone.org/ring/stan/iPhone_5-Alarm.mp3") {
// then lets create your document folder url
let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
// lets create your destination file url
let destinationUrl = documentsDirectoryURL.appendingPathComponent(audioUrl.lastPathComponent)
print(destinationUrl)
// to check if it exists before downloading it
if FileManager.default.fileExists(atPath: destinationUrl.path) {
print("The file already exists at path")
// if the file doesn't exist
} else {
// you can use NSURLSession.sharedSession to download the data asynchronously
URLSession.shared.downloadTask(with: audioUrl) { location, response, error in
guard let location = location, error == nil else { return }
do {
// after downloading your file you need to move it to your destination url
try FileManager.default.moveItem(at: location, to: destinationUrl)
print("File moved to documents folder")
} catch {
print(error)
}
}.resume()
}
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am using spring webflux functional style.
I want to create a endpoint which accepts large image files and send this files to another service with webClient in streaming way.
All file processing should be in streaming way because I don't want to my app crush because of outofmemory.
Is there anyway to do this ?
Probably something like this:
#PostMapping(value = "/images/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Mono<ResponseEntity<Void>> uploadImages(#RequestPart("files") Flux<FilePart> fileParts) {
return fileParts
.flatMap(filePart -> {
return webClient.post()
.uri("/someOtherService")
.body(BodyInserters.fromPublisher(filePart.content(), DataBuffer.class))
.exchange()
.flatMap(clientResponse -> {
//some logging
return Mono.empty();
});
})
.collectList()
.flatMap(response -> Mono.just(ResponseEntity.accepted().build()));
}
This accepts MULTIPART FORM DATA where you can attach multiple image files and upload them to another service.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a pdf file in my server and i want a method to download the pdf file and extract images from that file. So far i have used XamiTextSharpLGPLv2, pdfbox but no luck so far.
PdfReader reader = new PdfReader(new Uri(url));
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfDictionary pg = reader.GetPageN(i);
iTextSharp.text.pdf.PdfObject PDFObj = reader.GetPdfObject(i);
if ((PDFObj != null) && PDFObj.IsStream())
{
iTextSharp.text.pdf.PdfStream PDFStremObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
try
{
//var pdfImage = new PdfImageObject((PRStream)PDFStremObj);
//var img = pdfImage.GetDrawingImage();
}
catch (Exception)
{
}
}
}
PdfImageObject is not found in XamiTextSharpLGPLv2,
how can i use XamiTextSharpLGPLv2 to extract images or suggestions for any other library to achieve this would be a great help.
Thanks in advance.
Xamarin Extract Images from pdf file
here are two libraries to extract images from pdf file
XFINIUM.PDF
PDFTron
I have enabled itune file sharing in my Application.
I have added pdf file in my application directory.
now I want to search that file using my app. and upload it on server.
also if there multiple file and folder I want to show in application. search folder and select specific file and upload it. please suggest best way for doing that.
Appriciate for help.
do
{
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
print(dirPaths)
let Pnames = try NSFileManager.defaultManager().contentsOfDirectoryAtPath(dirPaths) as [String]
var ProductImgs:Array<String> = Array<String>()
var ProductNames:Array<String> = Array<String>()
for name in Pnames
{
let fileName:String = name
if fileName.hasSuffix(".pdf")
{
PdfURLs.append(dirPaths.stringByAppendingString("/\(fileName)"))
PdfNames.append(fileName)
print(dirPaths.stringByAppendingString("/\(fileName)"))
}
}
}
catch
{
print(error)
}
If you are fine using third party libraries, it would be great to use Alamofire. It is an HTTP networking library written in Swift.
You can upload the file easily using this one,
let fileURL = NSBundle.mainBundle().URLForResource("Default", withExtension: "png")
Alamofire.upload(.POST, "https://httpbin.org/post", file: fileURL)
For a complete understanding of this library check out this link, https://github.com/Alamofire/Alamofire
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am about to start writing a program that will have a GUI interface with the user that prompts for a number between 1-100. The program then emails me that number(this program would be running on an unknown users computer).
I am unable to decide what programing language to use for such a project. Can anyone suggest a language that is able to do GUI, and send emails from someone elses computer? (Preferable be able to save this program as a .exe or some single file that can be run from their computer. Also would prefer a link as to how to email in that language, but I am fine doing that research myself, just unsure what language to start researching in. If I left anything out please leave a comment asking for clarification. Thanks for any help I can get.
Use C# cus you know it's awesome (heavily biased answer) and here's the code
private bool sendMsg (string from, string to, string subject , string messageBody)
{
MailMessage message = null;
try
{
message = new MailMessage(from, to);
using (message) {
message.Subject = subject;
//message.CC.Add(CCemailAddress);
message.Body = messageBody;
message.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.outlook.com", 587);
client.Credentials = new System.Net.NetworkCredential(from, "Sending Accounts Password");
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true; //enable SSL
client.Send(message);
client.Dispose();
}
}
catch
{
return false;
}
message.Dispose();
return true;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Somebody can explain me this code :
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
var auth = new MvcAuthorizer
{
Credentials = new SessionStateCredentials()
{
ConsumerKey = this.client.ConsumerKey,
ConsumerSecret = this.client.ConsumerSecret,
OAuthToken = identity.Token.Token
}
};
the difference between the two codes
Thanks,
Logically, there is no difference. I'm making the assumption that "credentials" in the first example is a SessionStateCredentials that was instantiated previously in the code. The second example uses object initialization syntax to do the same thing.