Skip to content

Commit e27c47f

Browse files
authored
Allow file arguments with URL value (#494)
* Revert "Visualise hero image from URL (#492)" This reverts commit 3b4f9c0. * Allow URL file arguments to download content
1 parent 1e3771d commit e27c47f

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/FileTransferManager.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,25 @@ private void downloadHelper(
122122
String httpMethod = request.getHttpMethod();
123123
try {
124124
if (url == null) {
125-
op = new NetworkOperation(
126-
hostName,
127-
servlet,
128-
dict,
129-
httpMethod,
130-
APIConfig.getInstance().getApiSSL(),
131-
Constants.NETWORK_TIMEOUT_SECONDS_FOR_DOWNLOADS);
125+
// Download it directly if the argument is URL.
126+
// Otherwise continue with the api request.
127+
if (path != null && (path.startsWith("http://") || path.startsWith("https://"))) {
128+
op = new NetworkOperation(
129+
path,
130+
httpMethod,
131+
path.startsWith("https://"),
132+
Constants.NETWORK_TIMEOUT_SECONDS_FOR_DOWNLOADS);
133+
134+
} else {
135+
op = new NetworkOperation(
136+
hostName,
137+
servlet,
138+
dict,
139+
httpMethod,
140+
APIConfig.getInstance().getApiSSL(),
141+
Constants.NETWORK_TIMEOUT_SECONDS_FOR_DOWNLOADS);
142+
}
143+
132144
} else {
133145
op = new NetworkOperation(
134146
url,

AndroidSDKCore/src/main/java/com/leanplum/messagetemplates/options/RichHtmlOptions.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private static String readFileAsString(ActionContext context, String name) {
120120

121121
/**
122122
* Replace all keys with __file__ prefix to keys without __file__ prefix and replace value of
123-
* those keys with local path to file. In case of URL it will leave the value unchanged.
123+
* those keys with local path to file.
124124
*
125125
* @param map Map with arguments from ActionContext.
126126
* @param htmlTemplateName Name of file with HTML template.
@@ -143,18 +143,13 @@ private static Map<String, Object> replaceFileToLocalPath(Map<String, Object> ma
143143
if (filePath == null) {
144144
continue;
145145
}
146-
if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
147-
map.put(key.replace(Values.FILE_PREFIX, ""), filePath);
148-
map.remove(key);
149-
} else {
150-
File f = new File(filePath);
151-
String localPath = "file://" + f.getAbsolutePath();
152-
if (localPath.contains(Leanplum.getContext().getPackageName())) {
153-
map.put(key.replace(Values.FILE_PREFIX, ""),
154-
localPath.replace(" ", "%20"));
155-
}
156-
map.remove(key);
146+
File f = new File(filePath);
147+
String localPath = "file://" + f.getAbsolutePath();
148+
if (localPath.contains(Leanplum.getContext().getPackageName())) {
149+
map.put(key.replace(Values.FILE_PREFIX, ""),
150+
localPath.replace(" ", "%20"));
157151
}
152+
map.remove(key);
158153
}
159154
}
160155
return map;

0 commit comments

Comments
 (0)