Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

How i can Share PDF File #15

Closed
ibenettaleb opened this issue May 29, 2018 · 6 comments
Closed

How i can Share PDF File #15

ibenettaleb opened this issue May 29, 2018 · 6 comments

Comments

@ibenettaleb
Copy link

I need to now how i can share pdf. file i have files in node js server i have a direct link to them how i can do that

@yasirkula
Copy link
Owner

yasirkula commented May 29, 2018

You can either share the download link as plain text (SetText), or download the PDF file to the device and then share it as a file (AddFile).

P.S. Sharing the download link as plain text may not work as desired; e.g. if user decides to share on Facebook, it will be shared as a link rather than as an attached file.

@ibenettaleb
Copy link
Author

You Can Put C# Example Code.

@yasirkula
Copy link
Owner

How do you plan to share the PDF? As a link or as a file?

@ibenettaleb
Copy link
Author

The PDF are in Node Js serve in Public folder i want to download and put it in piece joint send after that deleted

@yasirkula
Copy link
Owner

using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;

public void Share( string url )
{
	StartCoroutine( DownloadAndShare( url ) );
}

private IEnumerator DownloadAndShare( string url )
{
	// Credit: https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html
	var uwr = new UnityWebRequest( url, UnityWebRequest.kHttpVerbGET );
	string path = Path.Combine( Application.temporaryCachePath, "temp.pdf" );
	uwr.downloadHandler = new DownloadHandlerFile( path );
	
	yield return uwr.SendWebRequest();
	
	if( uwr.isNetworkError || uwr.isHttpError )
		Debug.LogError( uwr.error );
	else
		new NativeShare().AddFile( path ).Share();
	
	// It may not be safe to delete the file immediately afterwards,
	// maybe it is currently being shared? Instead, you can delete the file
	// at that "path" later in your app's lifecycle or when your app starts
	// File.Delete( path );
}

@ibenettaleb
Copy link
Author

Thank you very much #yasirkula you are awesome 👍 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants